#PHP, 53 bytes
PHP, 53 bytes
for($i=$n=$argv[1];--$i&&$n%$i;);echo!($i-1|$n+1&$n);
takes command line argument; prints 1 for Mersenne prime, empty string else.
Run with -r.
breakdown
for($i=$n=$argv[1];--$i&&$n%$i;); // loop $i down from $n-1 until $i divides $n
// If $n is prime, loop ends with $i=1. ($n=1 -> $i=0)
echo!($i-1|$n+1&$n); // If $i!=1, $n is not prime. If ($n+1&$n)>0, $n is not Mersenne.
// If either $i-1 or $n+1&$n is truthy, the negation will be false.
#PHP, 53 bytes
for($i=$n=$argv[1];--$i&&$n%$i;);echo!($i-1|$n+1&$n);
takes command line argument; prints 1 for Mersenne prime, empty string else.
Run with -r.
breakdown
for($i=$n=$argv[1];--$i&&$n%$i;); // loop $i down from $n-1 until $i divides $n
// If $n is prime, loop ends with $i=1. ($n=1 -> $i=0)
echo!($i-1|$n+1&$n); // If $i!=1, $n is not prime. If ($n+1&$n)>0, $n is not Mersenne.
// If either $i-1 or $n+1&$n is truthy, the negation will be false.
PHP, 53 bytes
for($i=$n=$argv[1];--$i&&$n%$i;);echo!($i-1|$n+1&$n);
takes command line argument; prints 1 for Mersenne prime, empty string else.
Run with -r.
breakdown
for($i=$n=$argv[1];--$i&&$n%$i;); // loop $i down from $n-1 until $i divides $n
// If $n is prime, loop ends with $i=1. ($n=1 -> $i=0)
echo!($i-1|$n+1&$n); // If $i!=1, $n is not prime. If ($n+1&$n)>0, $n is not Mersenne.
// If either $i-1 or $n+1&$n is truthy, the negation will be false.
#PHP, 53 bytes
for($i=$n=$argv[1];--$i&&$n%$i;);echo!($i-1|$n+1&$n);
takes command line argument; prints 1 for Mersenne prime, empty string else.
Run with -r.
breakdown
for($i=$n=$argv[1];--$i&&$n%$i;); // loop $i down from $n-1 until $i divides $n
// If $n is prime, loop ends with $i=1. ($n=1 -> $i=0)
echo!($i-1|$n+1&$n); // If $i!=1, $n is not prime. If ($n+1&$n)>0, $n is not Mersenne.
// If either $i-1 or $n+1&$n is truthy, the negation will be false.