From d4f3769a93cea62324c417ca72d6910b7585ecbe Mon Sep 17 00:00:00 2001 From: David M Peixotto Date: Thu, 6 Oct 2011 16:54:20 -0500 Subject: [PATCH] Added Queens benchmark from nofib It currently fails with a segfault, probably due to lack of heap overflow checks. --- tests/Nofib/Queens.hs | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 tests/Nofib/Queens.hs diff --git a/tests/Nofib/Queens.hs b/tests/Nofib/Queens.hs new file mode 100644 index 0000000..a2f527d --- /dev/null +++ b/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]