31 lines
675 B
Plaintext
31 lines
675 B
Plaintext
# project euler 46
|
||
|
||
# bool ? n
|
||
IsPrime ← memo(=1⧻°/×)
|
||
# [all primes below n] ? n
|
||
Primes ← +1⊚≡IsPrime↘1⇡
|
||
# [all squares below n] ? n
|
||
Squares ← ⍜√(↘1⇡+1⌊)
|
||
# check if n can be written as
|
||
# sum of prime and twice square
|
||
# bool ? n
|
||
Goldbach ← ±⧻⊚=⟜(
|
||
⊞+⊃(⍜÷₂Squares)Primes
|
||
)
|
||
# [all odd composites on [a, b)] ? a b
|
||
OddComposites ← ▽¬⊸∊ Primes⟜(
|
||
+1 +⤙(⍜÷₂(⇡⌊) ⌵-) ⊙⍜÷₂⌊
|
||
):
|
||
# [n subintervals a_b] ? a b n
|
||
Subintervals ← ⧈₂/⊂+⟜(×⇡+1⤙(˜÷⌵-))
|
||
|
||
⊢⊙◌⍢(
|
||
+300.◌
|
||
⤚(
|
||
Subintervals⊙⊙8
|
||
⍚/OddComposites⌊
|
||
/◇⊂⍚(▽¬⊸≡Goldbach)
|
||
)
|
||
| ¬±⧻
|
||
) [] 3
|