Created
January 1, 2019 23:57
-
-
Save kenprice/7e1df85030605ff304df6ee682bf0159 to your computer and use it in GitHub Desktop.
Euler Project Problem 577
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
triangularNumbers = [ quot (x^2 + x) 2 | x <- [1..12345] ] | |
hexSums' :: Int -> [Int] -> [Int] | |
hexSums' n sumList = | |
if allZeroes sumList then | |
sumList | |
else | |
zipWith (+) sumList nextList | |
where | |
nextList = hexSums' (n+1) (take 12345 nextTriNums) | |
nextTriNums = padding ++ map (*(n+1)) triangularNumbers | |
padding = replicate (n*3) 0 | |
hexSums = hexSums' 1 triangularNumbers | |
hexes :: Int -> Int | |
hexes n = n | |
allZeroes :: [Int] -> Bool | |
allZeroes xs = and $ map (== 0) xs | |
main :: IO() | |
main = putStrLn $ show $ sum $ take 12343 hexSums |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment