Open Side Menu Go to the Top
Register
Prime numbers Prime numbers

03-26-2011 , 10:58 AM
I love prime numbers, and they have some amazing applications in cryptography as well as some other things.

This is a pretty useless application of primes, but it's a good demonstration I wrote to show off one of the amazing properties of prime numbers.

Given a word, work out if one word is a scrambled version of another. IE, boat and btoa is true, but bota and booat is false. Same number of characters, same characters.

Quote:
a=[2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61, 67,71,73,79,83,89,97,101];
function b(c)
{
r=1;
for(i=0;i<c.length;i++)
r*=a[c[i].charCodeAt(0)-97];
return r
}
Then do:

Quote:
alert(b("hello")==b("elloh"));
(It's obfuscated a bit as it was for a competition, it's the least obfuscated one I've got)

Anyone else got any interesting prime number snippets or applications? I'd love to see them!
Prime numbers Quote
03-26-2011 , 03:21 PM
Interesting. I think that algorithm is in principle similar to the numbering scheme invented by Godel

http://en.wikipedia.org/wiki/G%C3%B6del_numbering

Although in that case Godel was also interested in being able to deconstruct the numbered elements.

In any case, yay prime numbers?
Prime numbers Quote
03-26-2011 , 04:40 PM
Not sure if you've seen this before: http://www.suffecool.net/poker/evaluator.html

Interesting poker-programming use of prime numbers.

Juk
Prime numbers Quote
03-26-2011 , 05:22 PM
Ah yes, juk, for my uni project I did something similar to that at used it as my main material. It made an interesting 2+2 let me see if i can find it
Prime numbers Quote
03-26-2011 , 05:24 PM
LOL yeah one of my first posts!

http://forumserver.twoplustwo.com/45...valuators-597/

It's an interesting read if your into optimisations and stuff relating to poker.
Prime numbers Quote
03-26-2011 , 06:55 PM
"an interesting 2+2" is quite the understatement, that thread advanced the state of the art in hand evaluation by leaps and bounds IIRC! Still goes way over my head though!
Prime numbers Quote
03-26-2011 , 07:55 PM
Prime numbers can do quite cruel things to your mind imo, even tho they have some kind of magical beauty to them.

http://projecteuler.net/index.php?section=problems
Prime numbers Quote
03-27-2011 , 03:37 AM
Quote:
Originally Posted by wellju
Prime numbers can do quite cruel things to your mind imo, even tho they have some kind of magical beauty to them.

http://projecteuler.net/index.php?section=problems
This link is entirely too much fun. I've gotten through 17 so far.
Prime numbers Quote
03-27-2011 , 01:50 PM
Quote:
Originally Posted by Gullanian
LOL yeah one of my first posts!

http://forumserver.twoplustwo.com/45...valuators-597/

It's an interesting read if your into optimisations and stuff relating to poker.
Ah yeah, that was an awesome thread! Didn't realize it was you who started it.

Juk
Prime numbers Quote
03-27-2011 , 08:16 PM
That was a truly epic thread and I've probably read it top to bottom 4 or 5 times.
Prime numbers Quote
03-31-2011 , 10:30 PM
Anybody want to form a team on GIMPS (http://mersenne.org/gettingstarted/)?

Last edited by jukofyork; 04-01-2011 at 08:43 AM. Reason: Fixed broken URL.
Prime numbers Quote
04-05-2011 , 11:52 PM
Quote:
Originally Posted by Gullanian

Given a word, work out if one word is a scrambled version of another. IE, boat and btoa is true, but bota and booat is false. Same number of characters, same characters.
Nice. Same approach used in Cactus Kev's Pokerhand Evaluator
Prime numbers Quote
04-15-2011 , 08:12 PM
I don't know if this is considered programming-related but here's an interesting way to generate a texture (wallpaper, background, whatever) which looks random but only takes a single tile and some mathemagicks to generate (using prime numbers, ofc).

http://designfestival.com/the-cicada...web-designers/
Prime numbers Quote
04-15-2011 , 08:17 PM
Quote:
Originally Posted by Styhn
I don't know if this is considered programming-related but here's an interesting way to generate a texture (wallpaper, background, whatever) which looks random but only takes a single tile and some mathemagicks to generate (using prime numbers, ofc).

http://designfestival.com/the-cicada...web-designers/
Great article, highly recommend it!
Prime numbers Quote

      
m