FizzBuzz

Member
Posts: 567
Joined: 2004.07
Post: #1
I stole this one from xkcd, but it's simple and fun.

the objective is to print the numbers 1 through (and including!) 100 so that your (uncompiled, unless you're doing straight machine code) program uses as little size as possible.

Here's my ruby entry (64 bytes):
Code:
1.upto(100){|i|puts i%3*i%5>0?i:"FizzBuzz"[i%3<1?0:4,i%5<1?8:4]}

[edit]63 bytes:
Code:
1.upto(?d){|i|puts i%3*i%5>0?i:"FizzBuzz"[i%3<1?0:4,i%5<1?8:4]}
[/edit]

It's not magic, it's Ruby.
Quote this message in a reply
Luminary
Posts: 5,143
Joined: 2002.04
Post: #2
Er, your description of the task is rather lacking Rasp

The task is to print Fizz for numbers that are a multiple of 3, Buzz for numbers that are a multiple of 5, FizzBuzz for numbers that are a multiple of both, and otherwise, the number itself.

Anyway, don't you think that "desu " programs are more interesting? http://desudesudesu.net/ Wink
Quote this message in a reply
Member
Posts: 567
Joined: 2004.07
Post: #3
oh yes, rather, that's the description Rasp

And where is forth on that page?

It's not magic, it's Ruby.
Quote this message in a reply
Luminary
Posts: 5,143
Joined: 2002.04
Post: #4
There's an email to submit desu programs to at the bottom...
Quote this message in a reply
Sage
Posts: 1,403
Joined: 2005.07
Post: #5
parse error
1.upto(100){|i|puts i%3*i%5>0?i:"FizzBuzz"[i%3<1?0:4,i%5<1?8:4]}

Sir, e^iπ + 1 = 0, hence God exists; reply!
Quote this message in a reply
Member
Posts: 567
Joined: 2004.07
Post: #6
runs fine for me on ruby 1.8.2, outputing:
Code:
1
2
Fizz
4
Buzz
Fizz
7
8
Fizz
Buzz
11
Fizz
13
14
FizzBuzz
16
17
Fizz
19
Buzz
Fizz
22
23
Fizz
Buzz
26
Fizz
28
29
FizzBuzz
31
32
Fizz
34
Buzz
Fizz
37
38
Fizz
Buzz
41
Fizz
43
44
FizzBuzz
46
47
Fizz
49
Buzz
Fizz
52
53
Fizz
Buzz
56
Fizz
58
59
FizzBuzz
61
62
Fizz
64
Buzz
Fizz
67
68
Fizz
Buzz
71
Fizz
73
74
FizzBuzz
76
77
Fizz
79
Buzz
Fizz
82
83
Fizz
Buzz
86
Fizz
88
89
FizzBuzz
91
92
Fizz
94
Buzz
Fizz
97
98
Fizz
Buzz

It's not magic, it's Ruby.
Quote this message in a reply
Post Reply