Chris
Chris

Reputation: 1128

Is it possible to optimize this expression

check x = filter((==0) . (\(x,y) -> x `mod` y)) $ zip (replicate 20 x)  [1..20]
main = do 
   print $ take 1 $ filter ((==20) . length) [check x | x <- [1..]]

I'm trying to run the above via http://www.compileonline.com/compile_haskell_online.php but it appears to be using too much resources as the number being evaluated increases and so I can search for filter(==18) but not filter(>=19). Is there anyway to optimize the expression so that it would run?

Upvotes: 0

Views: 108

Answers (1)

Sassa NF
Sassa NF

Reputation: 5406

I think here the task must be solved completely differently.

It looks like you are looking for the first number that can be divided by all numbers [1..20]. I propose you find all prime divisors of all numbers in the range, and find the product of maximum powers of all primes.

Upvotes: 7

Related Questions