Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

my first haskell program

Name: Anonymous 2012-05-25 23:27

tell me what you think, /prog/


modulus x y  =
    if x > y
        then modulus (x-y) y
        else x

fizzbuzz x y =
    if (x<=100) then
        do
            if ((mod x 15)==0)
                then putStrLn "fizzbuzz"
                else if ((mod x 5)==0) then putStrLn "buzz"
                else if ((mod x 3)==0) then putStrLn "fizz"
                else print x
            fizzbuzz (x+1) y
        else return()

main = fizzbuzz 1 100

Name: Anonymous 2012-05-26 0:11

Improved!


modulus x y
    | x > y = modulus (x-y) y
    | x <= y = x

fb x
    | (mod x 15) == 0 = putStrLn "fizzbuzz"
    | (mod x 3) == 0 = putStrLn "fizz"
    | (mod x 5) == 0 = putStrLn "buzz"
    | otherwise = print x

fizzbuzz x
    | x <= 100 =
        do
        (fb x)
        (fizzbuzz (x+1))
    | x > 100 = return()

main = fizzbuzz 0

Name: Anonymous 2012-05-26 7:10


fizzbuzz = map fb [1..]
    where
    fb n | n `mod`  3 == 0 = "Fizz"
         | n `mod`  5 == 0 = "Buzz"
         | n `mod` 15 == 0 = "FizzBuzz"
         | otherwise       = show n

main = mapM_ putStrLn $ take 100 fizzbuzz

Name: Anonymous 2012-05-26 7:12

>>6
disregard that I suck cocks


fizzbuzz = map fb [1..]
    where
    fb n | n `mod` 15 == 0 = "FizzBuzz"
         | n `mod`  3 == 0 = "Fizz"
         | n `mod`  5 == 0 = "Buzz"
         | otherwise       = show n

main = mapM_ putStrLn $ take 100 fizzbuzz

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List