Пепа обнови решението на 16.10.2013 12:37 (преди около 11 години)
+Integer#prime?
+ unless self == 1 or self == 0
+ (((2 ** self) - 2) % self == 0)? true : false
+ end
+end
+
+Integer#prime_factors
+ i=2; temp = self; factors = []
+ while i<=temp
+ while i.prime? and temp % i == 0
+ temp=temp/i; factors.push i
+ end
+ i+=1
+ end
+ return factors
+end
+
+class Integer
+ def harmonic
+ temp = self
+ def help_func(n,sum)
+ if n == 0
+ sum
+ else
+ help_func(n-1, sum += 1/n)
+ end
+ end
+ return help_func(temp,0)
+ end
+end
+
+class Integer
+ def digits
+ temp = self
+ digits_array = []
+ while temp > 0
+ digits_array.push( temp%10 )
+ temp = temp/10
+ end
+ return digits_array.reverse
+ end
+ end
+
+
+class Array
+ def average
+ sum = 0
+ size_array = self.size
+ self.each { |x| sum += x}
+ return sum/size_array
+ end
+end
+
+
+class Array
+ def drop_every n
+ new_array = []; i = 1
+ while i < self.size
+ if i % n != 0
+ new_array.push(self[i-1])
+ end
+ i += 1
+ end
+ return new_array
+end
+end
+
+
+Array#define combine_with(other)
+ i = 0; combined_array = []; max_size = [self.size , other.size]
+ for i in 0..max_size.max
+ i>=self.size ? combined_array.push(self[i]) : next
+
+ i>=other.size ? combined_array.push(other[i]) : next
+ end
+ return combined_array
+end
+