Code
Diff
  • 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
  • 11
    def divisors(n)
    
    2
        fact = [];
    
    2+
        fact = []
    
    33
        for i in 1.. (Math.sqrt(n)).floor
    
    44
            if n % i == 0 
    
    55
                fact << i
    
    6
                if n / i != i
    
    7
                    fact << n / i
    
    8
                end
    
    6+
                # more rubyish i think
    
    7+
                fact << (n / i) if (n / i) != i
    
    99
            end
    
    1010
        end
    
    11
        fact.sort!
    
    12
        return fact
    
    10+
        # no need for "return" in ruby
    
    11+
        fact.sort
    
    1313
    end