Problem 174
http://projecteuler.net/index.php?section=problems&id=174
まぁ、これもさっきと大して変わらない(と思う、もっと良い解法があるかも)。
import Data.List import Data.Array.IO n :: Integer n = 10^6 lamina :: Integer -> [Integer] lamina h = [l^2-h^2 | l <- [h+2,h+4..floor.sqrt.fromIntegral $ n + h^2]] main :: IO () main = do l <- newArray (1,fromIntegral n) 0 :: IO (IOUArray Int Int) mapM_ (incArray l).map fromIntegral.concatMap lamina $ [1..div n 2 - 2] print.length.filter (\x -> 1<=x && x<=10) =<< getElems l where incArray ar x = readArray ar x >>= writeArray ar x.succ