September 2017 Update
This commit is contained in:
parent
bba7bfd280
commit
ba8067c3b7
14570 changed files with 153136 additions and 63871 deletions
|
|
@ -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 ]
|
||||
|
|
|
|||
|
|
@ -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 []
|
||||
|
|
|
|||
11
Task/List-comprehensions/Haskell/list-comprehensions-3.hs
Normal file
11
Task/List-comprehensions/Haskell/list-comprehensions-3.hs
Normal 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)]
|
||||
_ -> []
|
||||
17
Task/List-comprehensions/Haskell/list-comprehensions-4.hs
Normal file
17
Task/List-comprehensions/Haskell/list-comprehensions-4.hs
Normal 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
|
||||
Loading…
Add table
Add a link
Reference in a new issue