Created
January 16, 2015 09:29
-
-
Save anonymous/fab2a72ad4093a212f56 to your computer and use it in GitHub Desktop.
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
# finds all of the factors of x and pushes them to an array a | |
def factor_finder(x,a) | |
n=0 | |
x.times do | |
n += 1 | |
if x % n == 0 | |
a.push(n) | |
end | |
end | |
end | |
# checks to see if x is prime | |
def prime_checker(x) | |
n = 2 | |
remainder = x % n | |
finished = false | |
while finished == false do | |
if n == x | |
puts "#{n} is prime" | |
finished = true | |
elsif remainder == 0 | |
puts "#{x} is not prime" | |
finished = true | |
else | |
n+=1 | |
finished = false | |
end | |
end | |
end | |
# creates an array to store results of factoring | |
#calls the method with the argument 28 | |
#puts the results | |
new_array = [] | |
factor_finder(28,new_array) | |
puts new_array | |
#this is supposed to take each element of the array and call the prime_checker method on those elements one by one | |
new_array.each do |n| | |
prime_checker(n) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment