Skip to content

Instantly share code, notes, and snippets.

@kenprice
Created January 1, 2019 23:57
Show Gist options
  • Save kenprice/7e1df85030605ff304df6ee682bf0159 to your computer and use it in GitHub Desktop.
Save kenprice/7e1df85030605ff304df6ee682bf0159 to your computer and use it in GitHub Desktop.
Euler Project Problem 577
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