Pythagorean triples computation
This is a beautiful example of List monad
import Control.Monad triples :: [(Int, Int, Int)] triples = do z <- [1 ..] x <- [1 .. z] y <- [x .. z] guard (x ^ 2 + y ^ 2 == z ^ 2) pure (x, y, z)
This is a beautiful example of List monad
import Control.Monad triples :: [(Int, Int, Int)] triples = do z <- [1 ..] x <- [1 .. z] y <- [x .. z] guard (x ^ 2 + y ^ 2 == z ^ 2) pure (x, y, z)