http://www.colorless-sight.jp/wiki/?ProjectEular%2FProblem11
-- 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] ]
|
最新の20件2023-08-12
2022-12-28
2017-08-15
2014-01-31
2014-01-29
2013-06-04
2012-11-23
2010-08-01
2010-07-24
Tweet
|