Skip to content

Instantly share code, notes, and snippets.

@lattenwald
Last active August 16, 2016 08:36
Show Gist options
  • Save lattenwald/bc97a668641df7e77ef0 to your computer and use it in GitHub Desktop.
Save lattenwald/bc97a668641df7e77ef0 to your computer and use it in GitHub Desktop.
Haskell triangle numbers
-- This is even slower than triangleNumsAlt, but this is exactly
-- THE function where I grocked lazy lists
triangleNums = map fst triangleNums'
where
triangleNums' = (1, 2) : map (\(n, i) -> (n+i, i+1)) triangleNums'
triangleNumsAlt = map (\i -> i * (i+1) `div` 2) [1..]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment