From c570de0f6916de0aab41d8f87f8e8728e37b80a9 Mon Sep 17 00:00:00 2001 From: Fredrik Robertsen Date: Sun, 21 Sep 2025 01:40:12 +0200 Subject: [PATCH] solve 46 in uiua (4 seconds) --- 46/main.ua | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 46/main.ua 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