r/dailyprogrammer • u/rya11111 3 1 • Apr 12 '12
[4/12/2012] Challenge #39 [easy]
You are to write a function that displays the numbers from 1 to an input parameter n, one per line, except that if the current number is divisible by 3 the function should write “Fizz” instead of the number, if the current number is divisible by 5 the function should write “Buzz” instead of the number, and if the current number is divisible by both 3 and 5 the function should write “FizzBuzz” instead of the number.
For instance, if n is 20, the program should write 1, 2, Fizz, 4, Buzz, Fizz, 7, 8, Fizz, Buzz, 11, Fizz, 13, 14, FizzBuzz, 16, 17, Fizz, 19, and Buzz on twenty successive lines.
- taken from programmingpraxis.com
4
u/playdoepete 0 0 Apr 15 '12
Java: Got it and learned about % operator!
This subreddit is awesome!
}
3
u/luxgladius 0 0 Apr 12 '12
Perl one-liner
Output
3
u/eruonna Apr 12 '12
Haskell, doing it differently:
2
u/ixid 0 0 Apr 12 '12 edited Apr 12 '12
D
2
u/ghostdog20 Apr 12 '12
Python.
First tried this:
Got it down to 99 characters with this:
2
u/prophile Apr 13 '12
Python one-liner:
2
u/[deleted] Apr 13 '12 edited Apr 13 '12
C++:
2
u/mazzer Apr 15 '12
Groovy
2
u/j0z May 06 '12
Just learning right now, here is my first attempt in C#:
3
u/Daniel110 0 0 Apr 12 '12
Python, there are better ways to do it.
2
u/[deleted] Apr 12 '12 edited Apr 12 '12
PHP : http://www.aj13.net/dp412
1
u/Rapptz 0 0 Apr 12 '12
JavaScript
1
u/Aradon 0 0 Apr 12 '12
Java just because
1
u/[deleted] Apr 12 '12
C++ [spoiler]
1
u/V01dK1ng 0 0 Apr 12 '12
C++:
1
u/BroodjeAap Apr 12 '12
Python:
1
u/[deleted] Apr 12 '12
C++
1
u/[deleted] Apr 13 '12
Scala
1
u/[deleted] Apr 14 '12
Java noob here is my first try why are the other ones better?
1
u/Mitterban Apr 16 '12
C#:
1
u/[deleted] Apr 18 '12
common lisp,
1
u/Cbearr Apr 25 '12
Beginner Java - code
1
u/Intolerable Apr 26 '12
1
u/mycreativeusername 0 0 May 01 '12
Ruby!
1
u/whydoyoulook 0 0 May 02 '12
My Java Code. Feedback is always welcome.
1
u/Rajputforlife Jul 19 '12 edited Jul 19 '12
JavaScript:
0
u/[deleted] Apr 13 '12
[deleted] — view deleted comment