Created
December 13, 2012 11:06
-
-
Save psychocandy/4275779 to your computer and use it in GitHub Desktop.
Ruby program which finds the biggest prime factors for a number.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def generate(n) | |
return [] if n == 1 | |
factor = (2..n).find { |x| n % x == 0 } | |
[factor] + generate(n / factor) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment