Даяна обнови решението на 15.10.2012 15:37 (преди около 12 години)
+#prime_divisors
+
+def prime(n)
+ index = 2
+ while index <= n / 2
+ return false if n % index == 0
+ index += 1
+ end
+ true
+end
+
+
+class Integer
+
+ def prime_divisors
+ current = 2
+ divisors = []
+ while current <= self.abs / 2
+ divisors << current if self.abs % current == 0 and prime current
+ current += 1
+ end
+ divisors << self.abs if divisors.empty?
+ divisors
+ end
+end
+
+
+
+
+#fizzbuzz
+
+class Range
+ def fizzbuzz
+ array = self.to_a
+ array.each_index do |n|
+ if array[n] % 15 == 0
+ array[n] = :fizzbuzz
+ elsif array[n] % 3 == 0
+ array[n] = :fizz
+ elsif array[n] % 5 == 0
+ array[n] = :buzz
+ end
+ end
+ array
+ end
+end
+
+
+
+
+
+#group_values
+
+class Hash
+ def group_values
+ group = Hash.new { |hash, key| hash[key] = [] }
+ each_key { |key| group[self[key]] << key }
+ group
+ end
+end
+
+
+
+
+#densities
+
+class Array
+ def densities
+ count_elements = []
+ each { |n| count_elements << count(n) }
+ count_elements
+ end
+end