Created
June 23, 2009 03:16
-
-
Save nbryan/134334 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| require "mathn" | |
| number, primes, factors = 600851475143, Prime.instance, [] | |
| for i in primes | |
| if number % i == 0 | |
| factors << i | |
| number = number / i | |
| redo | |
| elsif i > Math.sqrt(number) | |
| factors << number if number > 1 | |
| break | |
| end | |
| end | |
| print "Prime factors: #{factors}\n" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment