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

90% of /prog/ can't write FizzBuzz

Name: The antagonist 2008-04-25 12:38

Prove me wrong

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: Anonymous 2008-04-25 15:20

print+(Fizz)[$_%3].(Buzz)[$_%5]||$_ for 1..100

Name: Anonymous 2008-04-25 17:52

lol scalable

fizzBuzz =
   zipWith numMerge [1..100] $ foldl1 (zipWith (++))
                             $ map (uncurry pulse) [(3, "Fizz"), (5, "Buzz")]
   where
      pulse freq string = cycle $ replicate (freq - 1) [] ++ [string]
      numMerge num [] = show num
      numMerge _ string = string

main = mapM_ putStrLn fizzBuzz

Name: Anonymous 2008-04-26 4:21

>>71
if it's a multiple of 3 then the (b = !(i%5)) doesn't run.

print"Fizz"x!($_%3).Buzz x/0|5$/||$_,$/for 1..100

1[$101\>][$$[$2>][3-]#\[$4>][5-]#$@$@*[@$.@@]?~["Fizz"]?~["Buzz"]?"
"1+]#%


100 [ 1+ dup 5 mod zero? over 3 mod zero? 2dup or not [ 2drop . ] [ [ "Fizz" write ] when [ "Buzz" write ] when drop "" print ] if ] each

Name: Anonymous 2008-04-29 18:33


print"\n".join(map(lambda x:str([x,"Fizz","Buzz","FizzBuzz"][(x%3==0)+(x%5==0)*2]),range(1,101)))

Name: Anonymous 2008-05-01 11:54

>>166
That was so beautiful I had to post a version that actually works (I apologize if it was meant to be wrong).

#include <stdio.h>
int main(int i) {
    return i > 100 ? 0 : ((
         (!(i%3) && printf("Fizz"))
       + (!(i%5) && printf("Buzz"))
    ) || printf("%d",i), putchar('n'), main(i + 1));
}

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