forked from nominolo/lambdachine
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
It currently fails with a segfault, probably due to lack of heap overflow checks.
- Loading branch information
Showing
1 changed file
with
30 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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] |