Created
October 24, 2015 13:30
-
-
Save fieldstrength/35f5b8870c2913b56cf8 to your computer and use it in GitHub Desktop.
Pythagorean triples
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
$ ghci | |
GHCi, version 7.10.2: http://www.haskell.org/ghc/ :? for help | |
λ> let pythag n = [ (x,y,z) | x <- [1..n], y <- [1..x], z <- [1..n], x^2+y^2 == z^2 ] | |
λ> length $ pythag 100 | |
52 | |
λ> pythag 100 | |
[(4,3,5),(8,6,10),(12,5,13),(12,9,15),(15,8,17),(16,12,20),(20,15,25),(21,20,29),(24,7,25),(24,10,26),(24,18,30),(28,21,35),(30,16,34),(32,24,40),(35,12,37),(36,15,39),(36,27,45),(40,9,41),(40,30,50),(42,40,58),(44,33,55),(45,24,51),(45,28,53),(48,14,50),(48,20,52),(48,36,60),(52,39,65),(55,48,73),(56,33,65),(56,42,70),(60,11,61),(60,25,65),(60,32,68),(60,45,75),(63,16,65),(63,60,87),(64,48,80),(68,51,85),(70,24,74),(72,21,75),(72,30,78),(72,54,90),(72,65,97),(75,40,85),(76,57,95),(77,36,85),(80,18,82),(80,39,89),(80,60,100),(84,13,85),(84,35,91),(96,28,100)] | |
λ> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment