DEV Community

Discussion on: A Simple Method To Finding Prime Numbers.

Collapse
 
cuotos profile image
Dan P • Edited

As Thorsten already pointed out, (25 - 1) % 6 == 0, but 25 is also divisible by 5, therefore not a prime.

But that said, I like the article and you are clearly passionate about learning. I would recommend you take this opportunity to start looking at unit testing of code if you haven't already. Testing your code against a KNOWN set of correct / incorrect results. For example (I've done this in Golang, but with your grasp of different languages, the logic should make sense)

play.golang.org/p/ouuBBadcqHn

Quick and dirty, but for numbers up to 500 compare your logic to a KNOWN list (which was pre generated). This gives you confidence your code works.

My other MINOR feedback point would be the names of functions, they should clearly tell users what it does. Especially in Ruby that allows question marks in the names, and by convention should be used on functions that return boolean.

finding_primes(num) bool
vs
is_prime?(num) bool

It's a little thing that your future colleagues (and your future self when you look at old code), will thank you for.

Collapse
 
seanolad profile image
Sean

Okay, I'll remember that. Thanks man.