Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- module Main where
- import Data.Array (Array, (!), bounds, listArray)
- import Data.Ix (Ix, inRange, range)
- readArray :: (Ix i, Read e) => (i, i) -> String -> Array i e
- readArray bds = listArray bds . map read . words
- walkArray :: (Ix i) => Int -> i -> (i -> i) -> Array i e -> [e]
- walkArray n i step a = [a ! i' | i' <- take n . iterate step $ i,
- bounds a `inRange` i']
- plus :: (Integral a) => (a, a) -> (a, a) -> (a, a)
- (a1, b1) `plus` (a2, b2) = (a1 + a2, b1 + b2)
- p11 :: String -> Int
- p11 = maximum . map product . sequences . readArray ((0, 0), (19, 19))
- where
- dirs = [(0, 1), (1, 0), (1, 1), (1, -1)]
- sequences a = [walkArray 4 i f a | i <- range . bounds $ a,
- f <- map plus dirs]
- main :: IO ()
- main = do
- txt <- readFile "Data/p11.txt"
- print . p11 $ txt
Add Comment
Please, Sign In to add comment