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

deleted 254 characters in body
Source Link
Emigna
  • 53.2k
  • 5
  • 44
  • 164

05AB1E, 10(削除) 10 (削除ここまで) 8 bytes

Extremely inefficient.

DLDpÏD!f-pO;î

Try it online! or Try it online!a less efficient way of generating primes

Explanation

n = 10 used as example.

D # duplicate
 # STACK: 10, 10 
 L # range
  # STACK: 10, [1,2,3,4,5,6,7,8,9,10]
 D ! # duplicatefactorial
 # STACK: 10, [1,2,3,4,5,6,7,8,9,10], [1,2,3,4,5,6,7,8,9,10]3628800
 p f # isunique prime
 # STACK: 10, [1,2,3,4,5,6,7,8,9,10], [0,1,1,0,1,0,1,0,0,0]
 Ï # keep only the elements of a that are 1 in bfactors
 # STACK: 10, [2,3,5,7]
 - # subtract
 # STACK: [8,7,5,3]
 p # is prime
 # STACK: [0,1,1,1]
 O # sum
 # STACK: 3
 ; # divide by 2
 # STACK: 1.5
 î # round up
 # STACK: 2
 # implicit output

05AB1E, 10 bytes

DLDpÏ-pO;î

Try it online!

Explanation

n = 10 used as example.

D # duplicate
 # STACK: 10, 10 
 L # range
  # STACK: 10, [1,2,3,4,5,6,7,8,9,10]
 D # duplicate
 # STACK: 10, [1,2,3,4,5,6,7,8,9,10], [1,2,3,4,5,6,7,8,9,10]
 p  # is prime
 # STACK: 10, [1,2,3,4,5,6,7,8,9,10], [0,1,1,0,1,0,1,0,0,0]
 Ï # keep only the elements of a that are 1 in b
 # STACK: 10, [2,3,5,7]
 - # subtract
 # STACK: [8,7,5,3]
 p # is prime
 # STACK: [0,1,1,1]
 O # sum
 # STACK: 3
 ; # divide by 2
 # STACK: 1.5
 î # round up
 # STACK: 2
 # implicit output

05AB1E, (削除) 10 (削除ここまで) 8 bytes

Extremely inefficient.

D!f-pO;î

Try it online! or Try a less efficient way of generating primes

Explanation

n = 10 used as example.

D # duplicate
 # STACK: 10, 10 
 ! # factorial
 # STACK: 10, 3628800
 f # unique prime factors
 # STACK: 10, [2,3,5,7]
 - # subtract
 # STACK: [8,7,5,3]
 p # is prime
 # STACK: [0,1,1,1]
 O # sum
 # STACK: 3
 ; # divide by 2
 # STACK: 1.5
 î # round up
 # STACK: 2
 # implicit output
Source Link
Emigna
  • 53.2k
  • 5
  • 44
  • 164

05AB1E, 10 bytes

DLDpÏ-pO;î

Try it online!

Explanation

n = 10 used as example.

D # duplicate
 # STACK: 10, 10 
 L # range
 # STACK: 10, [1,2,3,4,5,6,7,8,9,10]
 D # duplicate
 # STACK: 10, [1,2,3,4,5,6,7,8,9,10], [1,2,3,4,5,6,7,8,9,10]
 p # is prime
 # STACK: 10, [1,2,3,4,5,6,7,8,9,10], [0,1,1,0,1,0,1,0,0,0]
 Ï # keep only the elements of a that are 1 in b
 # STACK: 10, [2,3,5,7]
 - # subtract
 # STACK: [8,7,5,3]
 p # is prime
 # STACK: [0,1,1,1]
 O # sum
 # STACK: 3
 ; # divide by 2
 # STACK: 1.5
 î # round up
 # STACK: 2
 # implicit output

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