June 2018 Update
This commit is contained in:
parent
ba8067c3b7
commit
22f33d4004
5278 changed files with 84726 additions and 14379 deletions
12
Task/Factors-of-an-integer/Ruby/factors-of-an-integer-3.rb
Normal file
12
Task/Factors-of-an-integer/Ruby/factors-of-an-integer-3.rb
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
require 'prime'
|
||||
|
||||
def factors m
|
||||
return [1] if 1==m
|
||||
primes, powers = Prime.prime_division(m).transpose
|
||||
ranges = powers.map{|n| (0..n).to_a}
|
||||
ranges[0].product( *ranges[1..-1] ).
|
||||
map{|es| primes.zip(es).map{|p,e| p**e}.reduce :*}.
|
||||
sort
|
||||
end
|
||||
|
||||
[1, 7, 45, 100].each{|n| p factors n}
|
||||
Loading…
Add table
Add a link
Reference in a new issue