summaryrefslogtreecommitdiff
path: root/testsuite/tests/dph/diophantine/DiophantineVect.hs
diff options
context:
space:
mode:
Diffstat (limited to 'testsuite/tests/dph/diophantine/DiophantineVect.hs')
-rw-r--r--testsuite/tests/dph/diophantine/DiophantineVect.hs38
1 files changed, 38 insertions, 0 deletions
diff --git a/testsuite/tests/dph/diophantine/DiophantineVect.hs b/testsuite/tests/dph/diophantine/DiophantineVect.hs
new file mode 100644
index 0000000000..bef6694b3d
--- /dev/null
+++ b/testsuite/tests/dph/diophantine/DiophantineVect.hs
@@ -0,0 +1,38 @@
+{-# LANGUAGE ParallelArrays #-}
+{-# OPTIONS -fvectorise -XParallelListComp #-}
+module DiophantineVect (solution3) where
+
+import Data.Array.Parallel
+import Data.Array.Parallel.Prelude.Int
+
+import qualified Prelude as P
+
+solution3'
+ = let
+ pow x i = productP (replicateP i x)
+ primes = [: 2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,71,73 :]
+ sumpri xx = productP [: pow p x | p <- primes | x <- xx :]
+ distinct xx = productP [: x + 1 | x <- xx :]
+
+ series :: [:Int:] -> Int -> [:[:Int:]:]
+ series xs n
+ | n == 1 = [: [: 0 :] :]
+ | otherwise = [: [: x :] +:+ ps
+ | x <- xs
+ , ps <- series (enumFromToP 0 x) (n-1) :]
+
+ prob x y
+ = let xx = [: (sumpri m ,m)
+ | m <- series (enumFromToP 1 3) x
+ , distinct [: x * 2 | x <- m :] > y :]
+ i = minIndexP [: a | (a, b) <- xx :]
+ in xx !: i
+ in
+ prob 7 2000
+
+solution3 :: (Int, PArray Int)
+{-# NOINLINE solution3 #-}
+solution3
+ = let (i, is) = solution3'
+ in
+ (i, toPArrayP is)