diff --git a/46/main.ua b/46/main.ua new file mode 100644 index 0000000..238e74c --- /dev/null +++ b/46/main.ua @@ -0,0 +1,30 @@ +# 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