Skip to content

Instantly share code, notes, and snippets.

@psychocandy
Created December 13, 2012 11:06
Show Gist options
  • Save psychocandy/4275779 to your computer and use it in GitHub Desktop.
Save psychocandy/4275779 to your computer and use it in GitHub Desktop.
Ruby program which finds the biggest prime factors for a number.
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