First commit of partial RosettaCode contents.

Pushing this for testing purposes. Lots of work still needed.
This commit is contained in:
Ingy döt Net 2013-04-08 13:02:41 -07:00
commit 1e05ecd7ee
781 changed files with 9080 additions and 0 deletions

View file

@ -0,0 +1,5 @@
main = mapM_ putStrLn $ take 100 fizzbuzz
fizzbuzz = zipWith (\x y -> if null y then show x else y) [1..] fbs
fbs = zipWith (++) (cycle ["","","Fizz"]) (cycle ["","","","","Buzz"])

View file

@ -0,0 +1,12 @@
import Control.Monad.State
import Control.Monad.Trans
import Control.Monad.Writer
main = putStr $ execWriter $ mapM_ (flip execStateT True . fizzbuzz) [1..100]
fizzbuzz :: Int -> StateT Bool (Writer String) ()
fizzbuzz x = do
when (x `mod` 3 == 0) $ tell "Fizz" >> put False
when (x `mod` 5 == 0) $ tell "Buzz" >> put False
get >>= (flip when $ tell $ show x)
tell "\n"

View file

@ -0,0 +1,6 @@
fizzBuzz :: Int -> String
fizzBuzz x
| x `mod` 5 == 0 && x `mod` 3 == 0 = "FizzBuzz"
| x `mod` 5 == 0 = "Buzz"
| x `mod` 3 == 0 = "Fizz"
| otherwise = show x

View file

@ -0,0 +1,7 @@
main = mapM_ (putStrLn . fizzbuzz) [1..100]
fizzbuzz x
| x `mod` 15 == 0 = "FizzBuzz"
| x `mod` 3 == 0 = "Fizz"
| x `mod` 5 == 0 = "Buzz"
| otherwise = show x