From: Patrick Hurley Date: 2007-06-03T13:38:56+09:00 Subject: Re: [QUIZ] FizzBuzz (#126) On 6/2/07, Sergey Volkov wrote: > ----- Original Message ----- > From: "Ari Brown" > To: "ruby-talk ML" > 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 > > > 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