Елена обнови решението на 14.10.2012 18:21 (преди около 12 години)
+class Integer
+ def prime_divisors
+ if self==0 or self.abs==1 then "nil"
+ else
+ prime_div=[]
+ divisor=2
+ while divisor < self.abs + 1
+ if self%divisor==0
+ is_prime=true
+ j=2
+ limit=divisor/2
+ while j<limit +1
+ is_prime=false if divisor%j==0
+ j+=1
+ end
+ prime_div << divisor if is_prime
+ end
+ divisor+=1
+ end
+ return prime_div
+ end
+ end
+end
+
+class Range
+ def fizzbuzz
+ fizzbuzz_arr=self.to_a
+ fizzbuzz_arr.each_with_index { |val, index|
+ fizzbuzz_arr[index]=:fizz if val%3==0 and val%5!=0
+ fizzbuzz_arr[index]=:buzz if val%5==0 and val%3!=0
+ fizzbuzz_arr[index]=:fizzbuzz if val%3==0 and val%5==0
+ }
+ return fizzbuzz_arr
+ end
+end
+
+class Hash
+ def group_values
+ group=Hash.new()
+ self.each_value{ |val|
+ val_keys=[]
+ self.each{ |key, value|
+ if val==value
+ val_keys << key
+ end
+ }
+ group[val]=val_keys
+ }
+ return group
+ end
+end
+
+class Array
+ def densities
+ dens=[]
+ self.each{|val|
+ count=0
+ self.each{|value|
+ if val==value
+ count+=1
+ end
+ }
+ dens << count
+ }
+ return dens
+ end
+end