Created
October 19, 2012 13:22
-
-
Save blerou/3918200 to your computer and use it in GitHub Desktop.
Let's play Haskell! - 1st session
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
-- az elso nyers megvalositas szambol -> szoveg | |
fizzbuzzText n = | |
if n `mod` 3 == 0 then | |
if n `mod` 5 == 0 then | |
"FizzBuzz" | |
else | |
"Fizz" | |
else | |
if n `mod` 5 == 0 then | |
"Buzz" | |
else | |
show n | |
-- binding letrehozas let in konstrukcioval | |
fizzbuzzTextLet n = | |
let | |
fizz = if n `mod` 3 == 0 then "Fizz" else "" | |
buzz = if n `mod` 5 == 0 then "Buzz" else "" | |
in fizz ++ buzz | |
-- binding letrehozas where konstrukcioval | |
fizzbuzzTextWhere n = fizz ++ buzz | |
where | |
fizz = if n `mod` 3 == 0 then "Fizz" else "" | |
buzz = if n `mod` 5 == 0 then "Buzz" else "" | |
-- maga a fizzbuzz list comprehension-nel | |
fizzbuzzListComp = [fizzbuzzText n | n <- [1..]] | |
-- maga a fizzbuzz mappel | |
fizzbuzzMap = map fizzbuzzTextLet [1..] | |
-- alternativ megvalositas, vegtelen listak + zip | |
threes = cycle ["", "", "Fizz"] | |
fives = cycle ["", "", "", "", "Buzz"] | |
fizzbuzzZip = zipWith (++) threes fives |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment