On Jun 2, 2007, at 7:06 AM, Daniel M. wrote:
Ruby Q. [email protected] writes:
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”.
Anyone care for a friendly game of golf?
I’ve got this in 67 characters…
Is that how you would solve it in your job interview? Just curious.
James Edward G. II
I’ve got this in 67 characters…
Actually, I’ve now got 65 character or 62 characters. The 62
character version interprets the specification literally by
printing “Fizz”, “Buzz” or “FizzBuzz” with the double
quotation marks 
Speaking of literal interpetation, the original Quiz post came across in
my mail with a number of non-standard ASCII characters wrapped around
the Fizz and Buzz text.
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â€Â.
I spent a bunch of time trying to figure out how to output those
(unsuccessfully) after getting my initial solution working. Based on a
number of the other posts on the topic it appears that the real
requirement was to output Fizz, Buzz or FizzBuzz only without the other
characters. Is that correct?
Just curious while I wait to post my first quiz submission.
–Bill
Actually, I’ve now got 65 character or 62 characters. The 62 character
version interprets the specification literally by printing “Fizz”,
“Buzz” or
“FizzBuzz” with the double quotation marks 
I’ll match your 62, but I’m still thinking that some clever tricks might
get it lower!
sh-3.2$ wc fizzbuzz.rb
0 2 62 fizzbuzz.rb
sh-3.2$ ruby fizzbuzz.rb | tail -11
“FizzBuzz”
91
92
“Fizz”
94
“Buzz”
“Fizz”
97
98
“Fizz”
“Buzz”
I golf too! 
I got to reach 56 bytes, but I highly doubt I can shave one more byte
from
it.
|William (Bill) Froelich|
WBF> I spent a bunch of time trying to figure out how to output
WBF> those (unsuccessfully) after getting my initial solution working.
WBF> Based on a number of the other posts on the topic it appears that
WBF> the real requirement was to output Fizz, Buzz or FizzBuzz only
WBF> without the other characters. Is that correct?
Yes. Probably this symbols came from non-standard quotation marks.
Sun P. wrote:
I golf too! 
I got to reach 56 bytes, but I highly doubt I can shave one more byte
from
it.
I can’t wait for tomorrow to see how you all got such ridiculously low
numbers =)
On 6/2/07, Sammy L. [email protected] wrote:
I’m down to 42 chars.
Just kidding
The best I could do was 74, and it looks crappy.
Todd
On 6/2/07, Sun P. [email protected] wrote:
I golf too! 
I got to reach 56 bytes, but I highly doubt I can shave one more byte from
it.
We failed, just look at the achieves, I do not consider that a spoiler
because I am sure James was aware of the Ruby ML community’s attempt
to get it to 56 bytes in March if I recall correctly.
And no I guess nobody would golf at a job interview unless it were for
the PGA of course.
Robert
I know at an interview I would start with (well not exactly, but this
makes checking golf results easier)…
pth
require “test/unit”
class TestFizzbuzz < Test::Unit::TestCase
def test_output
assert_equal(CORRECT,ruby fizzbuzz.rb
)
end
end
CORRECT = <<EOF
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
EOF
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Yes, the task is to output the words “Fizz” and “Buzz” with no other
characters, it must be your email client playing up.
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.3 (GNU/Linux)
iD8DBQFGYc1V2vy7v+d+psQRAgbIAJ4pv+jdzhKjJUjVKAUkSHPWX0zoYQCfY+bn
YPrEzHRAHRtUBxYNLIkBhsA=
=rFW9
-----END PGP SIGNATURE-----
“Daniel M.” [email protected] wrote in message
news:[email protected]…
Ruby Q. [email protected] writes:
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”.
Anyone care for a friendly game of golf?
I’ve got this in 67 characters…
56 chars
see ‘Smallest FizzBuzz program’ thread in comp.lang.ruby
On Sun, Jun 03, 2007 at 02:35:02AM +0900, Joshua B. wrote:
Actually, I’ve now got 65 character or 62 characters. The 62 character
version interprets the specification literally by printing “Fizz”,
“Buzz” or
“FizzBuzz” with the double quotation marks 
I’ll match your 62, but I’m still thinking that some clever tricks might
get it lower!
I’ve got 60 now. But it sounds like the magic target is 56 
On 6/2/07, Ari B. [email protected] wrote:
Apparently this does not work:
array = []
array = array << (1…100)
who knew! Not I,
help?
thanks,
---------------------------------------------------------------|
What you create above is an array with an element that is a range, so:
irb(main):001:0> array = []
=> []
irb(main):002:1> array << (1…100) #you don’t need 'array = ’ in front
of this
=> [1…100]
irb(main):003:2> array
=> [1…100]
irb(main):004:0> array.class
=> Array
irb(main):005:0> array[0].class
=> Range
irb(main):006:0> array << “blah”
=> [1…100, “blah”]
I’m guessing you want an array created from a range? If so, one way
would be:
irb(main):007:0> array = (1…10).to_a
=> [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
Also, some range methods return an array (like (1…100).map {} for
example).
----- Original Message -----
From: “Ari B.” [email protected]
To: “ruby-talk ML” [email protected]
Sent: Saturday, June 02, 2007 10:12 PM
Subject: Re: [QUIZ] FizzBuzz (#126)
…
Also, i seem to be unable to put a range into an array. Yes, i
understand this is very simple, but when I did what I THOUGHT would
work, I can’t get a range of numbers to be inserted into an array.
Apparently this does not work:
array = []
array = array << (1…100)
array = (1…100).to_a
or
array = [*1…100]
or (golfers favorite?)
array = *1…100
or (if you need to add it to existing array):
array.push *1…100
On Jun 2, 2007, at 10:56 AM, Ivo D. wrote:
when s+1==y && s-1==q
Alrighty - looks good so far. When would it be appropriate to use ‘and’?
Also, i seem to be unable to put a range into an array. Yes, i
understand this is very simple, but when I did what I THOUGHT would
work, I can’t get a range of numbers to be inserted into an array.
Apparently this does not work:
array = []
array = array << (1…100)
who knew! Not I,
help?
thanks,
---------------------------------------------------------------|
~Ari
Extra bonus fun question: If gsub! doesn’t work for integers, what
could I use?
On 6/2/07, Sergey V. [email protected] wrote:
Apparently this does not work:
Don’t forget these:
?d
is the same as 100 and save a character
puts :Fizz
will print Fizz, just as well as :Fizz and saves a character, and if
you really want to save a couple chars figure out how to only have the
Fizz and Buzz literals and combine them in the multiple of 15 space.
All that having been said, my solution (not golfed) will include
something like:
module Enumerable
def map_every(n)
m = n - 1
result = []
self.each_with_index do |elem,i|
if i % n == m
result << yield(elem,i)
else
result << elem
end
end
result
end
end
On 6/3/07, Sergey V. [email protected] wrote:
or (golfers favorite?)
not quite
array = *1…100
array=*1…?d

Robert
A non-golf solution of mine :
for n in (1…100)
if n%3==0 && n%5==0
puts “FizzBuzz”
elsif n%3==0
puts “Fizz”
elsif n%5==0
puts “Buzz”
else
puts n
end
end
Does above code fit for a job interview? 
On 6/3/07, Sun P. [email protected] wrote:
puts n
end
end
Does above code fit for a job interview? 
No idea, the recruiters are not here yet, they will arrive in an hour
and half 
R.
S.Volkov wrote:
56 chars
see ‘Smallest FizzBuzz program’ thread in comp.lang.ruby
Darn, just wanted to write that I got a 58 one here. We had that in
#ruby-lang once too and golfed about it a bit. IIRC we had a smaller one
than 58 (didn’t store it back then), but I don’t remember how small. If
somebody knows blinks e-mail…
Regards
Stefan