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 32 characters in body
Source Link
J. Sallé
  • 3.5k
  • 10
  • 24

APL (Dyalog Unicode), 4039 bytes

⎕CY'dfns'⋄
{1↓(10pco(⍵+0 ⍵⍵+0⍵))/(-⍵)↑⍳⍵+⍵-1}

Try it online! Try it online!

The characters B← are not counted towards the byte count because they're unnecessary and are added to TIO so it's easier to call the function. Also, ⍎'⎕CY''dfns''⋄⍬' is the equivalent to ⎕CY'dfns'⋄, but TIO doesn't accept the usual APL notation for that, so the extra characters are needed.

Thanks to @ErikTheOutgolfer for 1 byte.

How it works:

⎕CY'dfns'⋄ ⍝ Imports every direct function. This is needed for the primes function, 'pco'.
{1↓(10pco(⍵+0 ⍵⍵+0⍵))/(-⍵)↑⍳⍵+⍵-1} ⍝ Main function, prefix.
 (10pco ) ⍝ Calls the function 'pco' with the modifier 10, which lists every prime between the arguments:
 (⍵+0 ⍵⍵+0⍵) ⍝ Vector of arguments, ⍵ and 2⍵.
 ⍝ The function returns a boolean vector, with 1s for primes and 0s otherwise.
 1↓ ⍝ Drops the first element of the vector (because Bertrands postulate excludes the left bound).
 / ⍝ Replicate right argument to match the left argument.
 ⍳⍵+⍵-1 ⍝ Generate range from 1 to 2⍵-1 (to exclude the right bound)
 ↑ ⍝ Take from the range
 (-⍵) ⍝ The last ⍵ elements.

APL (Dyalog Unicode), 40 bytes

⎕CY'dfns'⋄
{1↓(10pco(⍵+0 ⍵))/(-⍵)↑⍳⍵+⍵-1}

Try it online!

The characters B← are not counted towards the byte count because they're unnecessary and are added to TIO so it's easier to call the function. Also, ⍎'⎕CY''dfns''⋄⍬' is the equivalent to ⎕CY'dfns'⋄, but TIO doesn't accept the usual APL notation for that, so the extra characters are needed.

How it works:

⎕CY'dfns'⋄ ⍝ Imports every direct function. This is needed for the primes function, 'pco'.
{1↓(10pco(⍵+0 ⍵))/(-⍵)↑⍳⍵+⍵-1} ⍝ Main function, prefix.
 (10pco ) ⍝ Calls the function 'pco' with the modifier 10, which lists every prime between the arguments:
 (⍵+0 ⍵) ⍝ Vector of arguments, ⍵ and 2⍵.
 ⍝ The function returns a boolean vector, with 1s for primes and 0s otherwise.
 1↓ ⍝ Drops the first element of the vector (because Bertrands postulate excludes the left bound).
 / ⍝ Replicate right argument to match the left argument.
 ⍳⍵+⍵-1 ⍝ Generate range from 1 to 2⍵-1 (to exclude the right bound)
 ↑ ⍝ Take from the range
 (-⍵) ⍝ The last ⍵ elements.

APL (Dyalog Unicode), 39 bytes

⎕CY'dfns'⋄
{1↓(10pco(⍵+0⍵))/(-⍵)↑⍳⍵+⍵-1}

Try it online!

The characters B← are not counted towards the byte count because they're unnecessary and are added to TIO so it's easier to call the function. Also, ⍎'⎕CY''dfns''⋄⍬' is the equivalent to ⎕CY'dfns'⋄, but TIO doesn't accept the usual APL notation for that, so the extra characters are needed.

Thanks to @ErikTheOutgolfer for 1 byte.

How it works:

⎕CY'dfns'⋄ ⍝ Imports every direct function. This is needed for the primes function, 'pco'.
{1↓(10pco(⍵+0⍵))/(-⍵)↑⍳⍵+⍵-1} ⍝ Main function, prefix.
 (10pco ) ⍝ Calls the function 'pco' with the modifier 10, which lists every prime between the arguments:
 (⍵+0⍵) ⍝ Vector of arguments, ⍵ and 2⍵.
 ⍝ The function returns a boolean vector, with 1s for primes and 0s otherwise.
 1↓ ⍝ Drops the first element of the vector (because Bertrands postulate excludes the left bound).
 / ⍝ Replicate right argument to match the left argument.
 ⍳⍵+⍵-1 ⍝ Generate range from 1 to 2⍵-1 (to exclude the right bound)
 ↑ ⍝ Take from the range
 (-⍵) ⍝ The last ⍵ elements.
Source Link
J. Sallé
  • 3.5k
  • 10
  • 24

APL (Dyalog Unicode), 40 bytes

⎕CY'dfns'⋄
{1↓(10pco(⍵+0 ⍵))/(-⍵)↑⍳⍵+⍵-1}

Try it online!

The characters B← are not counted towards the byte count because they're unnecessary and are added to TIO so it's easier to call the function. Also, ⍎'⎕CY''dfns''⋄⍬' is the equivalent to ⎕CY'dfns'⋄, but TIO doesn't accept the usual APL notation for that, so the extra characters are needed.

How it works:

⎕CY'dfns'⋄ ⍝ Imports every direct function. This is needed for the primes function, 'pco'.
{1↓(10pco(⍵+0 ⍵))/(-⍵)↑⍳⍵+⍵-1} ⍝ Main function, prefix.
 (10pco ) ⍝ Calls the function 'pco' with the modifier 10, which lists every prime between the arguments:
 (⍵+0 ⍵) ⍝ Vector of arguments, ⍵ and 2⍵.
 ⍝ The function returns a boolean vector, with 1s for primes and 0s otherwise.
 1↓ ⍝ Drops the first element of the vector (because Bertrands postulate excludes the left bound).
 / ⍝ Replicate right argument to match the left argument.
 ⍳⍵+⍵-1 ⍝ Generate range from 1 to 2⍵-1 (to exclude the right bound)
 ↑ ⍝ Take from the range
 (-⍵) ⍝ The last ⍵ elements.

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