Sequence: smallest number with exactly n divisors: Difference between revisions
Sequence: smallest number with exactly n divisors (view source)
Revision as of 17:17, 23 July 2019
, 4 years ago→{{header|Ruby}}: Added Ruby
Catskill549 (talk | contribs) |
(→{{header|Ruby}}: Added Ruby) |
||
Line 808:
14 192
15 144
</pre>
=={{header|Ruby}}==
<lang ruby>func require 'prime'
def num_divisors(n)
n.prime_division.inject(1){|prod, (_p,n)| prod *= (n + 1) }
end
def first_with_num_divs(n)
(1..).detect{|i| num_divisors(i) == n }
end
p (1..15).map{|n| first_with_num_divs(n) }
</lang>
{{out}}
<pre>
[1, 2, 4, 6, 16, 12, 64, 24, 36, 48, 1024, 60, 4096, 192, 144]
</pre>
|