def divisors(n) fact = [] for i in 1.. (Math.sqrt(n)).floor if n % i == 0 fact << i # more rubyish i think fact << (n / i) if (n / i) != i end end # no need for "return" in ruby fact.sort end
- def divisors(n)
fact = [];- fact = []
- for i in 1.. (Math.sqrt(n)).floor
- if n % i == 0
- fact << i
if n / i != ifact << n / iend- # more rubyish i think
- fact << (n / i) if (n / i) != i
- end
- end
fact.sort!return fact- # no need for "return" in ruby
- fact.sort
- end