On Jun 3, 2007, at 9:40 , Joshua B. wrote:
Robert D. wrote:
Have been there, but this is not a valid solution, sorry to say so 
you gotta get rid of the quotes in the output.
Crud, I just tested at anarchy golf - FizzBuzz and youâre
rightâŚ
For those interested, the code was:
1.upto(?d){|i,x|i%5>0||x=:Buzz;p i%3>0?x||i:âFizz#{x}â}
s/p/puts/ and you get the proper solution:
1.upto(?d){|i,x|i%5>0||x=:Buzz;puts i%3>0?x||i:âFizz#{x}â}
Michael G.
grzm seespotcode net
On 6/3/07, Michael G. [email protected] wrote:
1.upto(?d){|i,x|i%5>0||x=:Buzz;p i%3>0?x||i:âFizz#{x}â}
s/p/puts/ and you get the proper solution:
if only âputsâ.length were âpâ.length 
On Jun 3, 2007, at 9:56 , Robert D. wrote:
rightâŚ
For those interested, the code was:
1.upto(?d){|i,x|i%5>0||x=:Buzz;p i%3>0?x||i:âFizz#{x}â}
s/p/puts/ and you get the proper solution:
if only âputsâ.length were âpâ.length 
s/proper solution/expected results/
And 59 isnât bad, I should think 
Michael G.
grzm seespotcode net
Here is my 56B
1.upto(?d){|x|x%5>0||b=:Buzz;puts x%3>0?b||x:âFizz%sâ%b}
I think my code looks similar to JoshuaâsâŚ
2007/6/3, Sun P. [email protected]:
On Jun 3, 2007, at 6:07 AM, Sun P. wrote:
A non-golf solution of mine :
Just as a reminder, please check that the no spoiler period has
expired before posting quiz solutions. Thank you.
James Edward G. II
My first thought:
(1âŚ100).each do |i|
case
when i % 15 == 0
puts âFizzBuzzâ
when i % 3 == 0
puts âFizzâ
when i % 5 == 0
puts âBuzzâ
else
puts i
end
end
If I took 30 seconds to think about it on an interview, I would have a
unit test (see my earlier post) and something like this:
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
result = *1âŚ100
result = result.map_every(3) { âFizzâ }
result = result.map_every(5) { âBuzzâ }
result = result.map_every(15) { âFizzBuzzâ }
puts result
I peeked on the mailing list, so I wonât participate in the golf
tournament â and I am not particularly good at golfing in any case.
pth
On Jun 3, 2007, at 8:17 , Michael G. wrote:
golf solution (67 chars)
1.upto(?d){|n|puts 0<n%3&&0<n%5?n:(1>n%3?âFizzâ:ââ)+(1>n%5?âBuzzâ:ââ)}
I canât count today: 70 chars.
Michael G.
grzm seespotcode net
On 6/1/07, Ruby Q. [email protected] wrote:
question as a screener:
Here is my nice, ungolfed version. But I took Peterâs Extra Credit
challenge.
class Integer
def inspect
x = (self % 3 == 0 ? âFizzâ : ââ)
x << ( self % 5 == 0 ? âBuzzâ : ââ )
x.empty? ? self : x
end
end
(1âŚ100).each {|x| p x}
I did this live in front of a friend, then he tried it in java. And
Obj-C. I beat him in time and line count for both. It was pretty
funny to watch him try.
Michael G. wrote:
s/proper solution/expected results/
And 59 isnât bad, I should think 
Michael G.
grzm seespotcode net
Thanks. Iâd push it a bit further, but I think Iâve already wasted
enough time golfing. This has gotten me thinking thoughâŚ
Mathematically speaking, finding the shortest/optimal solution to any
programming challenge is an NP problem. It might be fun to do a follow
up quiz where the goal is to write a code generator that can find the
elusive 56 byte golfing solution to the FizzBuzz quiz. If one were to
simply write a random ASCII string generator and test every possible 56
byte string, it would take less than 95^56 (or 5.656e110) iterationsâŚ
âŚor would that quiz be too hard?

-Josh
On Fri, 01 Jun 2007 21:28:14 +0900, Ruby Q. wrote:
Suggestion: A [QUIZ] in the subject of emails about the problem helps
everyone on Ruby T. follow the discussion. Please reply to the
original quiz message, if you can.
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
=-=-=-=-=
There has been some debate on the proper ways to screen programmers you
intend to hire. A common theory is that you really need to have the
programmer write some code for you to accurately gauge their skill.
Exactly what to have them write is another debate, but the blogosphere
has recently been abuzz with this question as a screener:
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ââŹÂ.
Pretend youâve just walked into a job interview and been hit with this
question. Solve it as you would under such circumstances for this weekâs
Ruby QâŚ
class Integer
def === num
num % self == 0
end
end
100.times do |x|
case x
when 15: puts âFizzBuzzâ
when 3: puts âFizzâ
when 5: puts âBuzzâ
else puts x
end
end
I have two solutions. One is the quick job interview version:
(1âŚ100).each { |x| str = ââ; str += âFizzâ if (x % 3).zero?; str +=
âBuzzâ if (x % 5).zero?; str = x if str.empty?; puts str }
The second is inspired by Peter S.'s early suggestion for âextra
funâ. Itâs not much different from the above, but it puts the logic
in Fixnum:
class Fixnum
def to_s
str = ââ
str += âFizzâ if (self % 3).zero?
str += âBuzzâ if (self % 5).zero?
str = â%dâ % self if str.empty?
str
end
end
(1âŚ100).each { |x| puts x }
My favorite thing about that solution is seeing irb prompts like
âirb(main):013:FizzBuzz>â and seeing that the range is output as
â1âŚBuzzâ
Daniel M. wrote:
The point is, yes, maintainability is important, but I really donât
understand the animosity towards âclevernessâ that seems to be showing
up here. That sounds to me dangerously close to the same attitude
that keeps ruby and many other non-mainstream languages out of many
production environments on the grounds that âweâll never be able to
find anyone to maintain itâ.
I suppose I should clarify what I mean by cleverness. I distinguish
between âcleverâ code and elegant code. Code that might be considered
clever but is in good taste I would term elegant. Golfing, fancy bit
manipulation by C programmers where the compiler would take care of it
anyway, etc. I term clever with a derogatory tone. The choice of terms
is almost entirely arbitrary. The point is that, as you said, in a job
interview what you want is a straightforward test of ability, not to
assess for on-the-spot puzzle solving ability.
Also, as a practical matter, I havenât seen this âclevernessâ in any
of the subsequent interviews Iâve conducted from the other side of the
desk. Frankly, Iâd love some evidence that incoming candidates had
been exposed to something other than the industry standard languages
and platforms. Exposure to functional programming and the thought
patterns that go with it is a good thing. Being able to look at a
problem from multiple angles is a good thing. Mental agility?
Weâre supposed to like that in a candidate.
Ya, thatâd be elegant. 
My first, obvious solution:
(1âŚ100).each do |i|
if (i % 3 == 0) and (i % 5 == 0)
puts âFizzBuzzâ
elsif (i % 3 == 0)
puts âFizzâ
elsif (i % 5 == 0)
puts âBuzzâ
else
puts i
end
end
Trying to reduce the redundant ifs:
(1âŚ100).each do |i|
s = ââ
s << âFizzâ if (i % 3 == 0)
s << âBuzzâ if (i % 5 == 0)
puts(s == ââ ? i : s)
end
The above seems unique among the solutions Iâve read so far.
Ryan
My solution: 63 characters without the quotes, or 60 characters with
them.
1.upto(100){|i|i%3==0&&x=âFizzâ;i%5==0&&x="#{x}Buzz";puts x||i}
1.upto(100){|i|i%3==0&&x=âFizzâ;i%5==0&&x="#{x}Buzz";p x||i}
On Sun, Jun 03, 2007 at 11:40:51PM +0900, Joshua B. wrote:
Crud, I just tested at anarchy golf - FizzBuzz and youâre
rightâŚ
For those interested, the code was:
1.upto(?d){|i,x|i%5>0||x=:Buzz;p i%3>0?x||i:âFizz#{x}â}
^^
Why the ,x here? x is locally scoped within the block anyway, and it
works
without it.
This solution cracked me up, but there is a typo in itâŚ
On Jun 3, 2007, at 9:49 AM, Fred P. wrote:
puts â59â
puts 'FizzBuzz
puts â61â
The middle line there is missing a quote. 
James Edward G. II
my first solution:
(1âŚ100).each do |n|
print :Fizz if (n % 3) == 0
print :Buzz if (n % 5) == 0
print n if (n % 3) != 0 and (n % 5) != 0
print â\nâ
end
and my second one:
(1âŚ100).each { |n| puts n % 3 == 0 ? n % 5 == 0 ? :FizzBuzz : :Fizz :
n % 5 == 0 ? :Buzz : n }
greets, paddor
2007/6/1, Ruby Q. [email protected]:
On 6/1/07, Ruby Q. [email protected] wrote:
Pretend youâve just walked into a job interview and been hit with this question.
Solve it as you would under such circumstances for this weekâs Ruby QâŚ
Iâd probably want to do something a little clever but not anything
too unorthodox, so hereâs my solution:
def replace(n,list=[[âFizzBuzzâ,15],[âBuzzâ,5],[âFizzâ,3]])
list.each { |r,m| return r if n % m == 0 }
return n
end
puts (1âŚ100).map { |e| replace(e) }
On 6/3/07, James Edward G. II [email protected] wrote:
This solution cracked me up, but there is a typo in itâŚ
On Jun 3, 2007, at 9:49 AM, Fred P. wrote:
puts â59â
puts 'FizzBuzz
puts â61â
The middle line there is missing a quote. 
But would you hire him (minus the typo)? Iâd be a bit worried that
heâd shown up for a job interview with a hangover 