Hi All,

Attached is my first submission to the Ruby Quiz.  I am relatively  
new to ruby (7 months) and I have never before been able to solve a  
Ruby Quiz without several days of head scratching effort. It is not  
the most ruby centric code, but it only took me 10 minutes to complete.

Don Levan
Brooklyn, New York


(1..100).each do |n|

   case
     when n.modulo(5) == 0 && n.modulo(3) == 0
     print 'FizzBuzz', ' '
     when n.modulo(5) == 0
     print 'Buzz', ' '
     when n.modulo(3) == 0
     print 'Fizz', ' '
     else
     print n, ' '
   end

end






On Jun 3, 2007, at 8:43 AM, Todd Benson wrote:

> -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- 
> =-=-=-=-=-=-=
>>
>> 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 Quiz.
>
> My "honest" solution (what I really would have submitted to the  
> interviewer):
>
> arr = (1..100).map do |i|
>  i = (("FizzBuzz" if i%15==0) or ("Fizz" if i%3==0) or ("Buzz" if i% 
> 5==0) or i)
> end
> puts arr
>
>
> I couldn't resist throwing in the Loki solution.  Why Loki?  Because
> it's a mischievous rascal, and it makes excessive use of the name
> "it", albeit misguidedly, which it thinks is fitting giving the recent
> hoopla about "it":
>
> require 'date'
>
> class Fixnum
>  @@shapes = {
>    3 => "Fizz",
>    5 => "Buzz"
>  }
>
>  def self.invoke it
>    @@shapes = it if it.kind_of? Hash
>  end
>
>  def self.reveal
>    puts @@shapes.value.join( ' ' )
>  end
>
>  def << it
>    return self if it.empty?
>    it
>  end
>
>  def options( sep="", it=[] )
>    @@shapes.keys.sort.each do |k|
>      it << @@shapes[k] if self%k == 0
>    end
>    self << it.join( sep )
>  end
> end
>
> loki_roused = ARGV[0]
>
> if loki_roused
>  the_simpsons = {
>    3=>"Homer",
>    5=>"Marge",
>    7=>"Bart",
>    11=>"Lisa",
>    13=>"Maggie"
>  }
>  Fixnum.invoke the_simpsons
> end
>
> (1..100).each do |i|
>  puts i.options
> end
>
> if loki_disturbed
>  jd = Date.today.jd
>  puts "\n---------------------------------"
>  puts "\n Out of the simpson family -- on this Julian day of #{jd},
> Loki can shape shift into:\n   #{(it = jd.options "
> ").kind_of?(String) ? it : 'none of them'}"
>  puts "---------------------------------\n"
> end
>
>
> Some thoughts:
>
> This is, obviously, an incredibly easy programming puzzle -- as far as
> writing down the pseudo code in english.  It took me, however, no lie,
> a good half hour just to decide on a course of action.  In my head, I
> struggled with the virtues of simplicity and the "coolness" of
> conciseness, all while trying to avoid mediocrity.  Actual programming
> was a breeze.  From there, though, no lie, at least fifteen minutes to
> debug.  I'm not kidding.
>
> Now, I'm the first to admit that I'm new to Ruby, and programming is
> not my strong suit, but I would never think that I'm one of those
> people that couldn't program themselves out of a paper bag.
>
> Thinking about this quiz just reinforced what I already knew about
> myself.  I'm not a guy who just jumps in and gets his hands dirty.  In
> fact, I'm the exact opposite.  I over-think the problem and often get
> nowhere.  If this were a test of performance under pressure, I'm
> certain I would have failed to impress during the interview.
>
> In any case, to the other newbies out there: don't be intimidated by
> such frivolous pursuits of the lofty few such as "golf".  In fact, be
> so bold as to join in if you dare.  But, as in all things, be
> steadfast in your Ruby endeavors.  Enlightenment will come :)
>
> Todd
>