Daily GUIDE-ance:

Tuesday, April 27, 2010

Here's an algorithm I made up while I was a work today for determining if a number is prime or not.


Let X= the number you want to know if its prime or not
Let Y=2

1)Check: is X divisible by Y?

If yes, X aint prime.

If no:

2) Check: Is Y^2 bigger than X?

If yes, X is prime.
If no, repeat the process, increasing Y by one.

You could also simply increase Y to the next highest prime and it'd work just as well, but since to determine if Y+1 is prime you have to work through a bunch of steps of the algorithm, vs just using that number means you only have to work through the steps once, so I figure its faster just to crank through all the numbers rather than trying to filter out the non primes.

I am putting this up here just in case you needed something like this. It's free.

A pleasant factiod that comes out of this is that any number lower than 49 (7x7) is prime, unless it ends in 0,2,4,5,6,8, or if its digits sum up to 3,6 or 9.

3 comments:

Hoba Chi said...

What did I ever do before this?!? I will just go back to picking colors for conditional formatting on my D & D character sheet in XLS format. ;)

Eyepoke said...

Does anybody NOT use XL for character sheets these days?

Seems like you'd be a fool not to.

For that matter, has Wizards/TSR come out with thier own software for D+D yet?

Renae said...

You go Brain Boy!