aboutsummaryrefslogtreecommitdiff
path: root/comparison/Haskell
diff options
context:
space:
mode:
Diffstat (limited to 'comparison/Haskell')
-rw-r--r--comparison/Haskell/Makefile7
-rw-r--r--comparison/Haskell/fib-38.hs6
-rw-r--r--comparison/Haskell/nqueen-12.hs21
3 files changed, 32 insertions, 2 deletions
diff --git a/comparison/Haskell/Makefile b/comparison/Haskell/Makefile
index 13a1b83..ee4e347 100644
--- a/comparison/Haskell/Makefile
+++ b/comparison/Haskell/Makefile
@@ -1,7 +1,7 @@
CC = stack ghc
CFLAGS = -O2
BENCHMARK = bash ../tools/sptest_commands.sh
-TARGET = ack3-11 fib38 bsort-20000 isort-20000 qsort-260000 msort-260000
+TARGET = nqueen-12 ack3-11 fib-38 bsort-20000 isort-20000 qsort-260000 msort-260000
LOG = log.txt
@@ -12,10 +12,13 @@ all: $(LOG)
$(LOG): $(TARGET)
$(BENCHMARK) $(TARGET)
+nqueen-12: nqueen-12.hs
+ $(CC) -- $(CFLAGS) $<
+
ack3-11: ack3-11.hs
$(CC) -- $(CFLAGS) $<
-fib38: fib38.hs
+fib-38: fib-38.hs
$(CC) -- $(CFLAGS) $<
bsort-20000: bsort-20000.hs
diff --git a/comparison/Haskell/fib-38.hs b/comparison/Haskell/fib-38.hs
new file mode 100644
index 0000000..658d228
--- /dev/null
+++ b/comparison/Haskell/fib-38.hs
@@ -0,0 +1,6 @@
+fib 0 = 0
+fib 1 = 1
+fib n = fib (n - 2) + fib (n - 1)
+
+
+main = print $ fib 38
diff --git a/comparison/Haskell/nqueen-12.hs b/comparison/Haskell/nqueen-12.hs
new file mode 100644
index 0000000..1efb57b
--- /dev/null
+++ b/comparison/Haskell/nqueen-12.hs
@@ -0,0 +1,21 @@
+member x [] = False
+member x (y:ys)
+ | x==y = True
+ | otherwise = member x ys
+
+threat k m [] = False
+threat k m (x:xs)
+ | (k == x-m) || (k == m-x) = True
+ | otherwise = threat (k+1) m xs
+
+
+queen1 0 b n = []
+queen1 m b n
+ | (member m b) || (threat 1 m b) = (queen1 (m-1) b n)
+ | (length b) == (n-1) = [m:b] ++ (queen1 (m-1) b n)
+ | otherwise = (queen1 n (m:b) n) ++ (queen1 (m-1) b n)
+
+queen n = queen1 n [] n
+
+n=12
+main = print $ (length (queen n))