http://www.colorless-sight.jp/wiki/?ProjectEular%2FProblem18
-- Problem 18 module Main (main) where main :: IO () main = do triangle_str <- getContents print $ problem18 $ to_triangle triangle_str to_triangle :: String -> [[Int]] to_triangle = map (map read . words) . lines problem18 :: [[Int]] -> Int problem18 tri = max_sum tri 0 0 max_sum :: [[Int]] -> Int -> Int -> Int max_sum tri i j | i+1 == length tri = tri !! i !! j | otherwise = tri !! i !! j + max left right where left = max_sum tri (i+1) j right = max_sum tri (i+1) (j+1) |
最新の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
|