Никола обнови решението на 14.10.2013 15:10 (преди около 11 години)
+class Integer
+
+ def prime?
+ if self > 1
+ not (2..self - 1).inject(false) { |so_far, i| so_far or (self % i).zero? }
+ else
+ false
+ end
+ end
+
+ def prime_factors
+ result = (2..self - 1).select { |i| (self % i).zero? and i.prime? }
+ #TODO times and negative
+ end
+
+ def harmonic
+ (1..self).inject { |so_far, i| so_far + i.to_r**-1 } #TODO test with 2.1
+ end
+
+ def digits
+ if self > 0
+ self.to_s.split('').map { |d| d.to_i }
+ else
+ (-self).digits
+ end
+ end
+
+end
+
+class Array
+
+ def frequencies
+ result = {}
+ self.each { |el| result[el] = result[el].to_i.next }
+ result
+ end
+
+ def average
+ self.reduce(:+) / self.size.to_f
+ end
+
+ #TODO drop_every(n) and combine_with(other)
+
+end