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;î
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
05AB1E, 10 bytes
DLDpÏ-pO;î
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