Last active
August 29, 2015 14:27
-
-
Save joegiralt/53a3caf8df1517d8b7d7 to your computer and use it in GitHub Desktop.
Project Euler 7
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
#Functional | |
require 'prime' | |
def find_10001_prime(array) | |
# array[0] incrementor | |
# array[1] number of time incremetor was prime | |
prime_but_not_10001 = Prime.instance.prime?(array[0]) && array[1] != 10001 | |
prime_10001 = Prime.instance.prime?(array[0]) && array[1] == 10001 | |
if prime_but_not_10001 | |
puts "#{array} prime_but_not_10001" | |
find_10001_prime([ array[0] + 1 , array[1] + 1 ]) | |
elsif prime_10001 | |
puts "#{array[0]} 10001th Prime!" | |
else | |
puts "#{array[0]} not a prime Prime!" | |
find_10001_prime([ array[0] + 1 , array[1] ]) | |
end | |
end | |
#find_10001_prime([0,0]) | |
#Imperative | |
require 'prime' | |
i = 0 | |
found_primes = 0 | |
while found_primes != 10001 | |
i = i +1 | |
if Prime.instance.prime?(i) | |
found_primes = found_primes + 1 | |
end | |
end | |
puts i |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment