Skip to content

Simplify primality test #153

@bkalcho

Description

@bkalcho

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:

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions