Сашо обнови решението на 15.10.2013 00:53 (преди около 11 години)
+#1
+class Integer
+ def prime?
+ i=2
+ return false if self<0
+ while(i<self/2)
+ return false if self%i==0
+ i+=1
+ end
+ return true
+ end
+#2
+def prime_factors
+ numbers = []
+ i=2
+ input=self
+ return prime_factors_help(i,input,numbers)
+end
+def prime_factors_help(i,input,numbers)
+ while(i<=input)
+ if input%i==0
+ numbers.push i
+ input=input/i
+ else
+ i+=1
+ end
+ end
+ return numbers
+end
+#3
+def harmonic
+ sum=0/1
+ i=1
+ while (i<=self)
+ sum+=1/i.to_r
+ i+=1
+ end
+ return sum
+end
+#4
+def digits
+ input=self.abs
+ number = []
+ while input>0
+ number.unshift input%10
+ input/=10
+ end
+ return number
+end
+end
+#5
+class Array
+ def frequencies
+ input = Hash.new 0
+ i=0
+ while i<self.size
+ input [self [i]]+=1
+ i+=1
+ end
+ return input
+ end
+#6
+ def average
+ i=0
+ sum=0.0
+ while i<self.size
+ sum+=self[i]
+ i+=1
+ end
+ return sum/i
+ end
+#7
+ def drop_every(n)
+ t=n
+ input = self
+ while t<=input.size
+ input.delete_at(t-1)
+ t+=n-1
+ end
+ return input
+ end
+#8
+ def combine_with(other)
+ bufer=[]
+ return self if other.empty?
+ return other if self.empty?
+ return bufer_fill(self,other,bufer)
+ end
+ def bufer_fill(self_input,other_input,bufer)
+ i=0
+ while i<self_input.size or i<other_input.size
+ bufer.push self_input[i] if self_input[i]
+ bufer.push other_input[i] if other_input[i]
+ i+=1
+ end
+ return bufer
+ end
+end