solve 46 in uiua (4 seconds)

This commit is contained in:
2025-09-21 01:40:12 +02:00
parent 28c16dec46
commit c570de0f69

30
46/main.ua Normal file
View File

@@ -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