September 2017 Update

This commit is contained in:
Ingy döt Net 2017-09-23 10:01:46 +02:00
parent bba7bfd280
commit ba8067c3b7
14570 changed files with 153136 additions and 63871 deletions

View file

@ -1,2 +1,7 @@
pyth :: (Enum t, Eq t, Num t) => t -> [(t, t, t)]
pyth n = [(x,y,z) | x <- [1..n], y <- [x..n], z <- [y..n], x^2 + y^2 == z^2]
pyth :: Int -> [(Int, Int, Int)]
pyth n =
[ (x, y, z)
| x <- [1 .. n]
, y <- [x .. n]
, z <- [y .. n]
, x ^ 2 + y ^ 2 == z ^ 2 ]

View file

@ -1,9 +1,8 @@
import Control.Monad (guard)
pyth :: (Enum t, Eq t, Num t) => t -> [(t, t, t)]
pyth :: Int -> [(Int, Int, Int)]
pyth n = do
x <- [1..n]
y <- [x..n]
z <- [y..n]
guard $ x^2 + y^2 == z^2
return (x,y,z)
x <- [1 .. n]
y <- [x .. n]
z <- [y .. n]
if x ^ 2 + y ^ 2 == z ^ 2
then [(x, y, z)]
else []

View file

@ -0,0 +1,11 @@
pyth :: Int -> [(Int, Int, Int)]
pyth n =
[1 .. n] >>=
\x ->
[x .. n] >>=
\y ->
[y .. n] >>=
\z ->
case x ^ 2 + y ^ 2 == z ^ 2 of
True -> [(x, y, z)]
_ -> []

View file

@ -0,0 +1,17 @@
pyth :: Int -> [(Int, Int, Int)]
pyth n =
concatMap
(\x ->
concatMap
(\y ->
concatMap
(\z ->
if x ^ 2 + y ^ 2 == z ^ 2
then [(x, y, z)]
else [])
[y .. n])
[x .. n])
[1 .. n]
main :: IO ()
main = print $ pyth 25