On Dec 4, 2005, at 9:03 AM, Paolo Capriotti wrote:
>> And immediately upon posting my first Ruby Quiz solution, I  
>> discovered a small bug.  :-{
>>
>> Perhaps someone will notice it.  :-)
>
> I've found this one:
>
> $ irb -r weird.rb
> irb(main):001:0> 4.divisors
> => [1, 2, 2, 4]
>
> :)

Exactly right.  :-)

I had previously written Integer#divisors something like this:

   def divisors
     list = (2..Math.sqrt(self).floor).select { |i| (self % i).zero? }
     list += list.collect { |i| self / i }
     [1, *list].uniq
   end

but forgot the value of calling Array#uniq upon simplifying and  
refactoring.

-- 
Rob Leslie
rob / mars.org