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

added 87 characters in body
Source Link
Business Cat
  • 9.2k
  • 1
  • 18
  • 37

CJam, (削除) 26 (削除ここまで) 27 bytes

ri){mp},{2b_1-,mp0円-,mp&},p

Straightforward algorithm, will golf further.

EDIT: Forgot n was inclusive.

Try it online!

For fun, this is very similar and also 27 bytes:

ri){_mp2円b_1-,mp0円-,mp&&},p

Explanation

ri e# Take an int as input
 ){mp}, e# Take the range up and including to the input, 
 e# including only prime numbers
 { e# For each prime...
 2b_ e# Convert it to binary and copy it
 1-,mp e# Take the top binary number, remove 1's, check if the length 
 e# is prime
 \ e# Swap top elements
 0-,mp e# Do the same but remove 0's
 & e# And
 }, e# Filter out primes for which the above block was false
 p e# Print nicely

CJam, (削除) 26 (削除ここまで) 27 bytes

ri){mp},{2b_1-,mp0円-,mp&},p

Straightforward algorithm, will golf further.

EDIT: Forgot n was inclusive.

Try it online!

Explanation

ri e# Take an int as input
 ){mp}, e# Take the range up and including to the input, 
 e# including only prime numbers
 { e# For each prime...
 2b_ e# Convert it to binary and copy it
 1-,mp e# Take the top binary number, remove 1's, check if the length 
 e# is prime
 \ e# Swap top elements
 0-,mp e# Do the same but remove 0's
 & e# And
 }, e# Filter out primes for which the above block was false
 p e# Print nicely

CJam, (削除) 26 (削除ここまで) 27 bytes

ri){mp},{2b_1-,mp0円-,mp&},p

Straightforward algorithm, will golf further.

EDIT: Forgot n was inclusive.

Try it online!

For fun, this is very similar and also 27 bytes:

ri){_mp2円b_1-,mp0円-,mp&&},p

Explanation

ri e# Take an int as input
 ){mp}, e# Take the range up and including to the input, 
 e# including only prime numbers
 { e# For each prime...
 2b_ e# Convert it to binary and copy it
 1-,mp e# Take the top binary number, remove 1's, check if the length 
 e# is prime
 \ e# Swap top elements
 0-,mp e# Do the same but remove 0's
 & e# And
 }, e# Filter out primes for which the above block was false
 p e# Print nicely
added 133 characters in body
Source Link
Business Cat
  • 9.2k
  • 1
  • 18
  • 37

CJam, 26(削除) 26 (削除ここまで) 27 bytes

ri){mp},{2b_1-,mp0円-,mp&},p

Straightforward algorithm, will golf further.

Try it online! EDIT: Forgot n was inclusive.

Try it online!

Explanation

ri e# Take an int as input
 ){mp}, e# Take the range up and including to the input, e# including only prime numbers
 { e# For each prime...
 2b_ e# Convert it to binary and copy it
 1-,mp e# Take the top binary number, remove 1's, check if the length 
 e#  is prime
 \ e# Swap top elements
 0-,mp e# Do the same but remove 0's
 & e# And
 }, e# Filter out primes for which the above block was false
 p e# Print nicely

CJam, 26 bytes

ri{mp},{2b_1-,mp0円-,mp&},p

Straightforward algorithm, will golf further.

Try it online!

Explanation

ri e# Take an int as input
 {mp}, e# Take the range up to the input, including only prime numbers
 { e# For each prime...
 2b_ e# Convert it to binary and copy it
 1-,mp e# Take the top binary number, remove 1's, check if the length is prime
 \ e# Swap top elements
 0-,mp e# Do the same but remove 0's
 & e# And
 }, e# Filter out primes for which the above block was false
 p e# Print nicely

CJam, (削除) 26 (削除ここまで) 27 bytes

ri){mp},{2b_1-,mp0円-,mp&},p

Straightforward algorithm, will golf further.

EDIT: Forgot n was inclusive.

Try it online!

Explanation

ri e# Take an int as input
 ){mp}, e# Take the range up and including to the input, e# including only prime numbers
 { e# For each prime...
 2b_ e# Convert it to binary and copy it
 1-,mp e# Take the top binary number, remove 1's, check if the length 
 e#  is prime
 \ e# Swap top elements
 0-,mp e# Do the same but remove 0's
 & e# And
 }, e# Filter out primes for which the above block was false
 p e# Print nicely
Source Link
Business Cat
  • 9.2k
  • 1
  • 18
  • 37

CJam, 26 bytes

ri{mp},{2b_1-,mp0円-,mp&},p

Straightforward algorithm, will golf further.

Try it online!

Explanation

ri e# Take an int as input
 {mp}, e# Take the range up to the input, including only prime numbers
 { e# For each prime...
 2b_ e# Convert it to binary and copy it
 1-,mp e# Take the top binary number, remove 1's, check if the length is prime
 \ e# Swap top elements
 0-,mp e# Do the same but remove 0's
 & e# And
 }, e# Filter out primes for which the above block was false
 p e# Print nicely

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