Write a program that prints the numbers from 1 to 100. But for multiples of three print "Fizz" instead of the number and for the multiples of five print "Buzz". For numbers which are multiples of both three and five print "FizzBuzz".
Name:
Anonymous2008-05-05 21:46
>>200
One less.
mapM_(\x->putStrLn$["FizzBuzz","Buzz","Fizz",show x]!!(signum(x`mod`3)+signum(x`mod`5)*2))[1..100]
This one is actually from http://hpaste.org/93, but seemed worth posting:
mapM_ putStrLn[cycle[show n,"Fizz","Buzz","FizzBuzz"]!!div(gcd n 15)2|n<-[1..100]]
void Main(int argc, char[][] agv) {
int num= 0;
start:
if(num = 100) {
goto end;
}
if (num < 100) {
num= num +1;
}
// print section
if (num % 3 = 0) {
cout<< "fizz";
}
if (num % 5= 0) {
cout<< "buzz;"
}
if (num %3= 0) {
if (num%5 =0) {
cout << "fizzbuzz";
}
}
goto start;
}
Name:
Anonymous2008-05-07 18:52
>>1
heh. ha ha. HA. HA HA HA. AH HAHAHAHAHAHAHA, OH GOD AH HAHAHAHAHAHAHAHA. BUHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHa....
Oh... oh...
That's a good one.
Name:
Anonymous2008-05-07 19:12
#light
let modcheck y =
match y with
| _ when y % 3 + y % 5 = 0 -> printfn "FizzBuzz"
| _ when y % 5 = 0 -> printfn "Buzz"
| _ when y % 3 = 0 -> printfn "Fizz"
| _ -> printfn "%d" y
let fizzbuzz =
let range = seq {1 .. 100}
range |> Seq.iter modcheck
fizzbuzz
(F#)
Name:
Anonymous2008-05-07 19:41
>>216 [/code]
That syntax looks
|_Absolutely
|_Horrid [/code]
let fizzbuzz =
let range = seq {1 .. 100}
let modcheck y =
match y with
| _ when y % 3 + y % 5 = 0 -> printfn "FizzBuzz"
| _ when y % 5 = 0 -> printfn "Buzz"
| _ when y % 3 = 0 -> printfn "Fizz"
| _ -> printfn "%d" y
range |> Seq.iter modcheck
//F# is beautiful so fuck off, every other piece of code in this thread is pretty much the same level of readability or worse.
fizzBuzz = mapM_ putStrLn $ map f [1..100]
where
f n | m3 n && m5 n = "FizzBuzz"
| m3 n = "Fizz"
| m5 n = "Buzz"
| True = show n
m3 n = mod n 3 == 0
m5 n = mod n 5 == 0