Skip to content

Commit

Permalink
Added Queens benchmark from nofib
Browse files Browse the repository at this point in the history
It currently fails with a segfault, probably due to lack of
heap overflow checks.
  • Loading branch information
dmpots committed Oct 6, 2011
1 parent 039228f commit d4f3769
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions 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]

0 comments on commit d4f3769

Please sign in to comment.