Христо обнови решението на 16.10.2013 03:00 (преди около 11 години)
+ def degree_of (dividend, divisor)
+ how_many_divides=[]
+ while dividend>1 and dividend % divisor == 0 do
+ how_many_divides += 1
+ dividend /= divisor
+ end
+ how_many_divides
+ end
+
+
+class Integer
+ #is the number prime
+ def prime?
+ current_divisior=2
+
+ if self <= 1 then return false end
+ while current_divisior <= Math.sqrt(self)
+ if self % current_divisior==0 then return false end
+ current_divisior+=1
+ end
+ true
+ end
+
+ def next_prime
+ copy_self = self + 1
+ copy_self += 1 until copy_self.prime?
+ copy_self
+ end
+ #return array with all prime dividers of
+ def prime_factors
+ copy_self,i = self.abs,2
+ prime_dividers = []
+ #6 lines...sure...
+ while copy_self > 1 do while copy_self % i == 0 do prime_dividers.push(i)
+ copy_self /= i
+ end
+ i=i.next_prime
+ end
+ prime_dividers
+ end
+
+ #n-th harmonic
+ def harmonic
+ sum = Rational(0, 1)
+ i=1
+ while i <= self do
+ sum += Rational(1, i)
+ i +=1
+ end
+ sum
+ end
+ #return an array with the digits of the number
+ def digits
+ copy_self = self.abs
+ all_digits = []
+
+ while copy_self > 0 do
+ all_digits.push copy_self%10
+ copy_self /= 10
+ end
+ all_digits.reverse
+ end
+end
+
+class Array
+
+ def frequencies
+ # all should be all_element_with_their_friequencies = {}
+ all = {}
+ #elements should be elements_of_the_array
+ self.each do |elements|
+ if(all[elements]) then all[elements] += 1 else all[elements] = 1 end
+ end
+ all
+ end
+
+ def average
+ sum = 0.0
+
+ self.each { |element_of_self| sum += element_of_self }
+ sum/self.length
+ end
+
+ def drop_every(n)
+ without_every_nth =[]
+ i = 0
+
+ while i < self.length do
+ without_every_nth.push self[i] unless i % n == n-1
+ i += 1
+ end
+ without_every_nth
+ end
+ def combine_with (other)
+ #6 lines... ok
+ end
+
+end