Skip to content

Instantly share code, notes, and snippets.

@RickArora
Created November 23, 2018 02:03
Show Gist options
  • Save RickArora/dee36ebec7e10ecfb9bb1582e1f44fc9 to your computer and use it in GitHub Desktop.
Save RickArora/dee36ebec7e10ecfb9bb1582e1f44fc9 to your computer and use it in GitHub Desktop.
# 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