Created
November 23, 2018 02:03
-
-
Save RickArora/dee36ebec7e10ecfb9bb1582e1f44fc9 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
# Write a method that returns a boolean indicating whether the argument is | |
# prime. | |
def prime?(num) | |
(1..num).each do |i| | |
if (num % i == 0 && i != 1 && i != num) || (num == 1) | |
return false | |
end | |
end | |
return true; | |
end | |
# Write a method that returns the number of prime factors of its argument. | |
def num_prime_factors(num) | |
newArray = [1] | |
(1..num).each do |i| | |
if (num % i == 0) && prime?(i) | |
newArray.push(i); | |
end | |
end | |
return newArray.length-1 | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment