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 13 characters in body
Source Link
Razetime
  • 27.6k
  • 3
  • 31
  • 77

APL (Dyalog Classic), (削除) 33 (削除ここまで) 31(削除) 31 (削除ここまで) 26 bytes

{⍵∊∊(((×ばつ⍨)1↓⍳)⍵)∘* ̈⍳⌈⍵*0.5∘* ̈⍳⍵}

-5 bytes from Kevin Cruijssen's suggestion.

Warning: Very, very slow for larger numbers.

Explanation

{⍵∊∊(((×ばつ⍨)1↓⍳)⍵)∘* ̈⍳⌈⍵*0.5∘* ̈⍳⍵} ⍵=n in all the following steps
 ⍳⌈⍵*0.5⍳⍵  range offrom 1 to ceil of sqrt(n)
 ∘* ̈ distribute power operator across left and right args
 (((×ばつ⍨)1↓⍳)⍵) list of primes till n
 ∊ flatten the right arg(monadic ∊)
 ⍵∊ is n present in the primes^(1..n)?

Try it online! Try it online!

APL (Dyalog Classic), (削除) 33 (削除ここまで) 31 bytes

{⍵∊∊(((×ばつ⍨)1↓⍳)⍵)∘* ̈⍳⌈⍵*0.5}

Explanation

{⍵∊∊(((×ばつ⍨)1↓⍳)⍵)∘* ̈⍳⌈⍵*0.5} ⍵=n in all the following steps
 ⍳⌈⍵*0.5 range of 1 to ceil of sqrt(n)
 ∘* ̈ distribute power operator across left and right args
 (((×ばつ⍨)1↓⍳)⍵) list of primes till n
 ∊ flatten the right arg(monadic ∊)
 ⍵∊ is n present in the primes^(1..n)?

Try it online!

APL (Dyalog Classic), (削除) 33 (削除ここまで) (削除) 31 (削除ここまで) 26 bytes

{⍵∊∊(((×ばつ⍨)1↓⍳)⍵)∘* ̈⍳⍵}

-5 bytes from Kevin Cruijssen's suggestion.

Warning: Very, very slow for larger numbers.

Explanation

{⍵∊∊(((×ばつ⍨)1↓⍳)⍵)∘* ̈⍳⍵} ⍵=n in all the following steps
 ⍳⍵  range from 1 to n
 ∘* ̈ distribute power operator across left and right args
 (((×ばつ⍨)1↓⍳)⍵) list of primes till n
 ∊ flatten the right arg(monadic ∊)
 ⍵∊ is n present in the primes^(1..n)?

Try it online!

Source Link
Razetime
  • 27.6k
  • 3
  • 31
  • 77

APL (Dyalog Classic), (削除) 33 (削除ここまで) 31 bytes

{⍵∊∊(((×ばつ⍨)1↓⍳)⍵)∘* ̈⍳⌈⍵*0.5}

Explanation

{⍵∊∊(((×ばつ⍨)1↓⍳)⍵)∘* ̈⍳⌈⍵*0.5} ⍵=n in all the following steps
 ⍳⌈⍵*0.5 range of 1 to ceil of sqrt(n)
 ∘* ̈ distribute power operator across left and right args
 (((×ばつ⍨)1↓⍳)⍵) list of primes till n
 ∊ flatten the right arg(monadic ∊)
 ⍵∊ is n present in the primes^(1..n)?

Try it online!

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