Skip to content

Commit

Permalink
2024 07 (uiua) part 2
Browse files Browse the repository at this point in the history
  • Loading branch information
memark committed Dec 29, 2024
1 parent d30ee88 commit 1446cb3
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 32 deletions.
2 changes: 1 addition & 1 deletion 2024/day-07/example.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@
161011: 16 10 13
192: 17 8 14
21037: 9 7 18 13
292: 11 6 16 20
292: 11 6 16 20
58 changes: 27 additions & 31 deletions 2024/day-07/main.ua
Original file line number Diff line number Diff line change
@@ -1,50 +1,46 @@
# https://adventofcode.com/2024/day/7

# uiua 0.14.0-dev.7
# uiua 0.15.0-dev.1
# Experimental!

# res ? [expr]
EvalMany ← (
&runc ⊂{"uiua" "eval" "--no-color"} □/◇$"_\n_"
⋅⊙◌ # keep stdout
🗄 ← (
⊜□⊸≠@\n
≡◇(↘₁♭₁regex "(\\d*): (.*)")
≡⊃(□◇⊜⋕⊸≠@\s⊣|⋕⊢)
)
┌─╴test
⍤⤙≍ {"9" "6"} EvalMany{"* 3 3" "+ 3 3"}
└─╴

# permutations ? length chars
Permute ← ⧅(1◌◌)
┌─╴test
┌─╴🧪
⍤⤙≍ ["++" "+*" "*+" "**"] Permute 2 "+*"
└─╴

# combs ? ops nums
Combine ← (
⊙≡(□$"_")
⊙¤
≡(/◇$"_ _"⊂↘1)
# ba ? a b
Join ← ⋕⊂:∩°⋕
┌─╴🧪
⍤⤙≍ 3412 Join 12 34
└─╴

# res ? nums ops
TryPerm ← (
°⊂ # extract first num
:⊙::
∧(⨬(×|+|Join) ⊗:"+*|")
)

# bool ? testvalue nums
TryEquation ← /∨= ⍜:(≡⋕EvalMany Combine Permute :"+*" ⊸⧻)
┌─╴test
⍤⤙≍ 1 TryEquation 3267 [81 40 27]
⍤⤙≍ 0 TryEquation 3267 [80 40 27]
⍤⤙≍ 1 TryEquation 292 [11 6 16 20]
└─╴
# bool ? ops nums testvalue
EvalEquation ← /∨= ≡⌞TryPerm :Permute : ⊙(-₁⊸⧻)

🐪 ← (
⊜(♭₁regex "(\\d*): (.*)")⊸≠@\n
≡⊃(□◇⊜⋕⊸≠@\s⊡₂|⋕⊡₁)
≡°⊟wait≡pool(
&pf@> :⟜TryEquation:°□ &pf@<
)
&p""
/+▽)
Solve! ← /+▽ °⊟⍉wait≡pool⍜:⟜◇(EvalEquation ^0 :)

┌─╴test
🐪 ← Solve!"+*" 🗄
┌─╴🧪
⍤⤙≍ 3749 🐪 &fras"example.txt"
⍤⤙≍ 3119088655389 🐪 &fras"input.txt"
└─╴

# ⧅(1◌◌) :"+*" 3, är detta bra?
🐫 ← Solve!"+*|" 🗄
┌─╴🧪
⍤⤙≍ 11387 🐫 &fras"example.txt"
⍤⤙≍ 264184041398847 🐫 &fras"input.txt"
└─╴

0 comments on commit 1446cb3

Please sign in to comment.