mirror of
https://github.com/TheAlgorithms/Ruby
synced 2024-11-16 19:50:00 +01:00
prime number: review comments-4 implementation
This commit is contained in:
parent
a864792884
commit
4af539f0c8
1 changed files with 7 additions and 12 deletions
|
@ -3,19 +3,14 @@
|
|||
|
||||
# Prime number check function
|
||||
def prime_number(number)
|
||||
non_prime_flag = false
|
||||
if number > 0
|
||||
if number == 1
|
||||
non_prime_flag = true
|
||||
elsif number == 2
|
||||
non_prime_flag = false
|
||||
elsif number % 2 == 0
|
||||
non_prime_flag = true
|
||||
else
|
||||
non_prime_flag = (2..Math.sqrt(number)).any? { |i| number % i == 0 }
|
||||
end
|
||||
else
|
||||
if number <= 1
|
||||
non_prime_flag = true
|
||||
elsif number == 2
|
||||
non_prime_flag = false
|
||||
elsif number % 2 == 0
|
||||
non_prime_flag = true
|
||||
else
|
||||
non_prime_flag = (2..Math.sqrt(number)).any? { |i| number % i == 0 }
|
||||
end
|
||||
|
||||
if !non_prime_flag
|
||||
|
|
Loading…
Reference in a new issue