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 Answer

Commonmark migration
Source Link

##Jelly, 5 bytes

Jelly, 5 bytes

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

B;ÆPP

Try it online!

How it works:

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 .

##Jelly, 5 bytes

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

B;ÆPP

Try it online!

How it works:

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 .

Jelly, 5 bytes

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

B;ÆPP

Try it online!

How it works:

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 .

deleted 59 characters in body
Source Link
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 .

##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 .

##Jelly, 5 bytes

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

B;ÆPP

Try it online!

How it works:

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 .

added 62 characters in body
Source Link
steenbergh
  • 8.2k
  • 1
  • 27
  • 43

##Jelly, 5 bytes

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

ÆP&BPB;ÆPP

Try it online! Try it online!

How it works:

ÆP Returns 1 if the input is a prime, 0 otherwise
B B Returns the binary representation of the input as a list [1, 0, 1, 1, ...]
 ; P Calculates theAnd productattach ofto thatthis list of 1's and 0's
 ÆP Since a Mersenne Prime1 isif onethe lessinput thanis a power of 2prime, its binary representation
is excusively 1's. The product is0 1.otherwise
 & P BitwiseCalculates ANDthe -product yieldsof 1this onlylist ifof left1's and right also yield 1.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 .

##Jelly, 5 bytes

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

ÆP&BP

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, ...]
 P Calculates the product of that 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 product is 1.
 & Bitwise AND - yields 1 only if left and right also yield 1.

##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 .

Source Link
steenbergh
  • 8.2k
  • 1
  • 27
  • 43
Loading

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