Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Added Queens benchmark from nofib

It currently fails with a segfault, probably due to lack of
heap overflow checks.
  • Loading branch information...
commit d4f3769a93cea62324c417ca72d6910b7585ecbe 1 parent 039228f
@dmpots authored
Showing with 30 additions and 0 deletions.
  1. +30 −0 tests/Nofib/Queens.hs
View
30 tests/Nofib/Queens.hs
@@ -0,0 +1,30 @@
+{-# LANGUAGE NoImplicitPrelude, MagicHash #-}
+-- RUN: %bc_vm_chk
+-- CHECK: @Result@ IND -> GHC.Bool.True`con_info
+-- XFAIL: *
+module Nofib.Queens where
+-- !!! count the number of solutions to the "n queens" problem.
+-- (grabbed from LML dist)
+
+import GHC.Types
+import GHC.Bool
+import GHC.Base
+import GHC.Num
+import GHC.List
+
+test = nsoln 10 == 724
+
+enumFromTo'Int :: Int -> Int -> [Int]
+enumFromTo'Int from@(I# m) to@(I# n) =
+ if m ># n then [] else
+ from : enumFromTo'Int (I# (m +# 1#)) to
+
+nsoln nq = length (gen nq)
+ where
+ safe :: Int -> Int -> [Int] -> Bool
+ safe x d [] = True
+ safe x d (q:l) = x /= q && x /= q+d && x /= q-d && safe x (d+1) l
+
+ gen :: Int -> [[Int]]
+ gen 0 = [[]]
+ gen n = [ (q:b) | b <- gen (n-1), q <- enumFromTo'Int 1 nq, safe q 1 b]
Please sign in to comment.
Something went wrong with that request. Please try again.