Орлин обнови решението на 10.10.2012 02:54 (преди около 12 години)
+class Integer
+ def prime_divisors
+ n = self
+ result = []
+ for divisor in 2.upto(self)
+ break if divisor > n
+ next if n % divisor != 0
+
+ result << divisor
+ while n % divisor == 0 do n /= divisor end
+ end
+ return result
+ end
+end
+
+class Range
+ def fizzbuzz
+ self.to_a.map {|x| case x % 15
+ when 3, 6, 9, 12
+ :fizz
+ when 5, 10
+ :buzz
+ when 0
+ :fizzbuzz
+ else
+ x
+ end }
+ end
+end
+
+class Hash
+ def group_values
+ value_hash = {}
+ self.each {|key, value| if value_hash.key? value
+ value_hash[value] << key
+ else
+ value_hash[value] = [key]
+ end }
+ return value_hash
+ end
+end
+
+class Array
+ def densities
+ density = Hash.new(0)
+ self.each {|x| density[x] += 1}
+ self.map {|x| density[x]}
+ end
+end