Skip to main content
We’ve updated our Terms of Service. A new AI Addendum clarifies how Stack Overflow utilizes AI interactions.
Code Golf

Return to Revisions

2 of 4
added 62 characters in body
steenbergh
  • 8.2k
  • 1
  • 27
  • 43

##Jelly, 5 bytes

Alternate approach to @Dennis' existing 5-byte Jelly answer:

B;ÆPP

Try it online!

How it works:

ÆP Returns 1 if the input is a prime, 0 otherwise
B Returns the binary representation of the input as a list [1, 0, 1, 1, ...]
 ; And attach to this list 
 ÆP a 1 if the input is a prime, 0 otherwise
 P Calculates the product of this list of 1's and 0's

Since a Mersenne Prime is one less than a power of 2, its binary representation is excusively 1's. The output therefor is 1 for Mersenne primes, and 0 in all other cases .

steenbergh
  • 8.2k
  • 1
  • 27
  • 43

AltStyle によって変換されたページ (->オリジナル) /