Ticket #3259: primes-test.hs

File primes-test.hs, 559 bytes (added by blamario, 5 years ago)

The main test file, with import instead of a local definition

Line 
1module Main where
2
3import Control.Parallel
4import Data.List (find)
5import Data.Maybe (maybe)
6
7import Parallelizable
8--parallelize a b = a `par` (b `pseq` (a, b))
9
10test :: Integer -> Integer -> Integer
11test n1 n2 = let (p1, p2) = parallelize
12                              (product $ factors $ product [1..n1])
13                              (product $ factors $ product [1..n2])
14             in p2 `div` p1
15
16{-# NOINLINE factors #-}
17factors n = maybe [n] (\k-> (k : factors (n `div` k))) (find (\k-> n `mod` k == 0) [2 .. n - 1])
18
19main = print (test 4000 4001)