Game Maker Games, Articles, Tutorials & More

Game Maker Network


Howdy, Guest! Please sign in or register an account.

Print

is_prime

By Daniel · January 5, 2009

A general primality test

// is_prime(n)
// A general primality test; an adaptation of code written by Yourself

if (argument0 < 4) return (argument0 > 1);
if !(argument0 mod 2 && argument0 mod 3) return false;

var a, m, d;
a[1] = 2; a[3] = 4; a[5] = 2; a[7] = 2; a[9] = 2;
m = sqrt(argument0);

for (d = 5; d < m; d += a[d mod 10])
  if (argument0 mod d == 0)
    return false;

return true;

Categories: Mathematics

Comments

There are no comments to display.

Post a Comment

You must be signed in to post comments.

Advertisement