Илиян обнови решението на 11.10.2012 00:36 (преди около 12 години)
+class Integer
+ def prime_divisors
+ worknumber = self.abs
+ result, div = [],1
+ while worknumber>1 and div+=1
+ result << div and worknumber/=div while worknumber%div==0
+ div = worknumber-1 if div > Math.sqrt(worknumber)
+ end
+ #(2..self).collect { |n| n if ((self/n) * n) == self and n.prime_divisors.len == 1}.compact
+ result.uniq
+ end
+end
+
+class Range
+ def fizzbuzz
+ result = self
+ result.collect do |z|
+ if z%3==0
+ if z%5==0
+ :fizzbuzz
+ else
+ :fizz
+ end
+ elsif z%5==0
+ :buzz
+ else
+ z
+ end
+ end
+ end
+end
+
+class Hash
+ def group_values
+ result = {}
+ self.keys.each do |k|
+ unless result.has_key?(self.fetch(k))
+ result[self.fetch(k)]=[]
+ end
+ result[self.fetch(k)]<<k
+ end
+ result
+ end
+end
+
+class Array
+ def densities
+ self.collect { |z| self.count(z) }
+ end
+end