Skip to content

Instantly share code, notes, and snippets.

@jdhuntington
Created August 26, 2009 15:52
Show Gist options
  • Save jdhuntington/175597 to your computer and use it in GitHub Desktop.
Save jdhuntington/175597 to your computer and use it in GitHub Desktop.
import Data.List
triangulate x = x * ( 1 + x ) / 2
pentagulate x = x * ( 3 * x - 1 ) / 2
hexagulate x = x * ( 2 * x - 1 )
triangles = [ triangulate x | x <- [1..] ]
pentagons = [ pentagulate x | x <- [1..] ]
memberOfIncreasingSequence x = (==x).head.dropWhile(<x)
isTriangle = flip memberOfIncreasingSequence triangles
isPentagon = flip memberOfIncreasingSequence pentagons
-- take 3 [ x | x <- [1..], isTriangle $ hexagulate x, isPentagon $ hexagulate x ]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment