Created
October 2, 2012 05:46
-
-
Save kunalbhatt/3816456 to your computer and use it in GitHub Desktop.
Primes Review
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
| def primes(num) | |
| primes = [ ] | |
| (2..num).each do |divider| | |
| until num % divider != 0 | |
| if num % divider == 0 | |
| primes << divider | |
| num = num/divider | |
| end | |
| end | |
| end | |
| primes | |
| end | |
| def primes num | |
| while num == 1 | |
| (2..num).each do |divider| | |
| original = num | |
| if num > 0 and divider = num-1 and num % divider == 0 | |
| primes << divider | |
| num = num/divider | |
| end | |
| end | |
| end | |
| puts primes(81).inspect |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment