Login Register






[Golfing] First 20 Mersenne primes filter_list
Author
Message
[Golfing] First 20 Mersenne primes #1
I haven't written a code golf challenge forever, and since the obfuscation thread seems to be popular, I thought I might keep that theme going. If you're unfamiliar with code golfing, it's a competition for the shortest possible version of a program.

For this challenge, write a program to calculate the first 20 Mersenne prime numbers. Since M20 has a whopping 1332 digits, print the exponential equation (2^p-1) instead of its value.

I'm working on a solution in Ruby, will post when it's finished.

Edit: I'll give anyone who can make it fit in a signature (<=242 characters with code tags) 20 NSP.
(This post was last modified: 02-10-2017, 10:52 PM by Inori.)
It's often the outcasts, the iconoclasts ... those who have the least to lose because they
don't have much in the first place, who feel the new currents and ride them the farthest.

Reply

RE: [Golfing] First 20 Mersenne primes #2
Ruby, 89 bytes. It's really inefficient, but it works perfectly. I'm gonna try and do more with it after work.

Code:
->f,n=1{puts"2^#{f-=1;n}-1"if->s{(0..n+=1).find{3>2|s=(s*s-2)%(2**n-1)}}[4]while f>0}[20]
It's often the outcasts, the iconoclasts ... those who have the least to lose because they
don't have much in the first place, who feel the new currents and ride them the farthest.

Reply

RE: [Golfing] First 20 Mersenne primes #3
Didn't understand yet? What is this?!
Die  But Don't Lie
“Oh Abu Dharr! Don’t look at the smallness of the sin but look at the one you disobeyed.” Prophet Muhammad (pbuh)
[Image: p_237m2jx1.png]
Click for Free VPN

Reply

RE: [Golfing] First 20 Mersenne primes #4
(02-10-2017, 07:13 PM)Mr.Kurd Wrote: Didn't understand yet? What is this?!

The task is to calculate the first 20 Mersenne primes (see link in OP) in as few characters as possible. Essentially, write a program to do it normally, then refactor it to the point where it can't get any smaller.
(This post was last modified: 02-10-2017, 07:35 PM by Inori.)
It's often the outcasts, the iconoclasts ... those who have the least to lose because they
don't have much in the first place, who feel the new currents and ride them the farthest.

Reply

RE: [Golfing] First 20 Mersenne primes #5
67 Bytes Mathematica
Always choose the best tool for the job
Code:
For[i=0,i<4424,i++,If[PrimeQ[2^i-1],Print[StringForm["2^``-1",i]]]]

Reply

RE: [Golfing] First 20 Mersenne primes #6
(02-11-2017, 01:38 AM)omega12 Wrote: 67 Bytes Mathematica
Always choose the best tool for the job
Code:
For[i=0,i<4424,i++,If[PrimeQ[2^i-1],Print[StringForm["2^``-1",i]]]]

If plugging in 4424 as a constant is legit, I can get mine down to 77. Would be better to treat it as unknown, imo.
Code:
4244.times{|n|puts"2^#{n}-1"if->s{(0..n+=1).find{3>2|s=(s*s-2)%(2**n-1)}}[4]}
It's often the outcasts, the iconoclasts ... those who have the least to lose because they
don't have much in the first place, who feel the new currents and ride them the farthest.

Reply

RE: [Golfing] First 20 Mersenne primes #7
Code:
Do[Print[StringForm["2^``-1",MersennePrimeExponent[n]]],{n,20}]
63 bytes
Why do function names need to be so long?

Reply

RE: [Golfing] First 20 Mersenne primes #8
(02-11-2017, 05:28 AM)omega12 Wrote:
Code:
Do[Print[StringForm["2^``-1",MersennePrimeExponent[n]]],{n,20}]
63 bytes
Why do function names need to be so long?

For real though, I implemented a function for it in about as many characters. Still better than Java's namespacing addiction.
It's often the outcasts, the iconoclasts ... those who have the least to lose because they
don't have much in the first place, who feel the new currents and ride them the farthest.

Reply