Кирчо обнови решението на 14.10.2012 16:14 (преди около 12 години)
+class Integer
+
+ def prime_divisors
+
+ def prime?(number)
+ (2...number.abs).each do |item|
+ return false if number % item == 0
+ end
+ true
+ end
+
+ result = Array.new
+ (2..self.abs).each do |item|
+ result << item if self % item == 0 and prime? item
+ end
+ result
+ end
+
+end
+
+class Range
+
+ def fizzbuzz
+
+ def fizzbuzz_set(value)
+ if value % 3 == 0
+ value % 5 == 0 ? :fizzbuzz : :fizz
+ else
+ value % 5 == 0 ? :buzz : value
+ end
+ end
+
+ result = Array.new
+ self.each { |item| result << fizzbuzz_set(item) }
+ result
+ end
+
+end
+
+class Hash
+
+ def group_values
+ result = Hash.new { |hash, key| hash[key] = Array.new }
+ self.each { |key, value| result[value] << key }
+ result
+ end
+
+end
+
+
+class Array
+
+ def densities
+
+ def contains_count(value, array)
+ count = 0
+ array.each do |item|
+ count += 1 if value == item
+ end
+ count
+ end
+
+ result = Array.new
+ self.each { |item| result << contains_count(item, self) }
+ result
+ end
+
+end