Simplify primality test
Author: bkalchoCreated Apr 18, 2023Updated Apr 18, 2023
Think this primality test should be simplified. You may use the following algorithm:
// 2 is a special case of prime, and if n < 2 then skip it. For others see bellow
if n > 2 {
for i := 2; i <= i/2; i++ {
if n % i == 0 {
break
//It's not a prime
}
}
// It's a prime
}I am referring to the simplification of the following part of the code: https://github.com/inancgumus/learngo/blob/e366d1a364eba61a08f84a17ef6dbf60818aa144/13-loops/exercises/10-crunch-the-primes/solution/main.go#L39
Source: inancgumus/learngo