Files
project_euler/46/main.ua

31 lines
675 B
Plaintext
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# 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