[Haskell-cafe] Efficiency question
rwiggerink at hotmail.com
Wed May 30 09:01:08 EDT 2007
> Counting can be done elegantly by 'filter' and 'length':
I figured out the following code after posting:
solve d = length [(y,x) | x <- [2..d], y <- [1..(x-1)], gcd x y == 1]
main = print (solve 1000000)
However when running it, it gave an answer of -1255316543. How on earth can
a length be negative?
> length $ filter (>1) $ Monad.liftM2 gcd [2..1000] [2..1000]
Thanks... now I'll just have to figure out what it does and why it does what
View this message in context: http://www.nabble.com/Efficiency-question-tf3823154.html#a10873232
Sent from the Haskell - Haskell-Cafe mailing list archive at Nabble.com.
More information about the Haskell-Cafe