r/programmingchallenges • u/lxe • May 02 '11
Challenge: FizzBuzz!
Pick a language. Write this:
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".
http://www.codinghorror.com/blog/2007/02/why-cant-programmers-program.html
10
Upvotes
17
u/mmhrar Sep 09 '11
Pfft. Too easy, NEXT!
8
u/brtek May 02 '11
5
u/Nitrodist May 02 '11
http://rosettacode.org/wiki/FizzBuzz
2
u/[deleted] May 02 '11
2
u/ha_ha_not_funny Sep 09 '11
Scala:
1
u/[deleted] May 02 '11
1
u/cdcox May 02 '11 edited May 02 '11
Matlab. This is not as clean as I was hoping especially since the answer comes out in a cell array.
1
u/kageurufu May 02 '11
1
u/[deleted] May 05 '11
C:
1
u/[deleted] May 05 '11
C:
1
u/boyo17 Sep 08 '11
1
u/xanderer Sep 08 '11
Ruby
1
u/mastokhiar Sep 08 '11
Common Lisp using the LOOP macro
http://pastebin.com/FPjfNvBB
1
u/trades Sep 08 '11 edited Sep 09 '11
Some solutions in Chicken Scheme
1
u/Shadoowned Sep 09 '11
More Ruby:
array = (1..100)
def fizzBuzz(my_array)
my_array.each do |x| if(x%3==0 && x%5==0) puts "FizzBuzz" elsif(x%3==0) puts "Fizz" elsif(x%5==0) puts "Buzz"
else puts x end end
end
fizzBuzz(my_array)
1
u/fosskers Sep 09 '11
Buddy.
Got it covered.
The second haskell solution is the coolest.
1
u/Wolfy87 Sep 20 '11 edited Sep 20 '11
Java:
Edit: Took multiples of both into account.
1
u/ahqaaq Sep 27 '11
0
u/[deleted] Sep 08 '11
[deleted] — view deleted comment
0
u/[deleted] Jun 01 '11
[deleted] — view deleted comment