https://www.colorless-sight.jp:443/wiki/?ProjectEular%2FProblem11
[[ProjectEular]] -- Problem 11 module Main (main) where main :: IO () main = do grid_str <- getContents print $ problem11 $ to_grid grid_str problem11 :: [[Int]] -> Int problem11 = maximum . prods to_grid :: String -> [[Int]] to_grid = map (map read . words) . lines prods :: [[Int]] -> [Int] prods grid = [ prod4 grid (x,y) (dx,dy) | x <- [0..19], y <- [0..19], (dx,dy) <- [ (1,0), (0,1), (1,1), (-1,1) ] ] prod4 :: [[Int]] -> (Int,Int) -> (Int,Int) -> Int prod4 grid (x,y) (dx,dy) | not (elem (x + 3*dx) [0..19]) || not (elem (y + 3*dy) [0..19]) = 0 | otherwise = product [ grid !! (y+t*dy) !! (x+t*dx) | t <- [0..3] ]