
10 Mar
2010
10 Mar
'10
9:21 a.m.
Stephen Tetley
oddSquareSum :: Integer oddSquareSum = sum . takeWhile (<10000) . filter odd . map (^2) $ [1..]
Why filter out the evens after generating them?
In other words: sum . takeWhile (<10000) . filter odd . map (^2) $ [1..] Since odd (x^2) => odd x: sum . takeWhile (<10000) . map (^2) $ [1,3..] Although it doesn't matter (more than a constant at any rate) for complexity, why generate values only to trim them later? Since x^2 < 10000 => x < 100: sum $ map (^2) [1,3..99] -k -- If I haven't seen further, it is by standing in the footprints of giants