Skip to content

Commit

Permalink
2024 05 (uiua) refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
memark committed Jan 2, 2025
1 parent 1446cb3 commit 717e2be
Showing 1 changed file with 28 additions and 44 deletions.
72 changes: 28 additions & 44 deletions 2024/day-05/main.ua
Original file line number Diff line number Diff line change
@@ -1,58 +1,42 @@
# https://adventofcode.com/2024/day/5

# Uiua 0.14.0-dev.6
# uiua 0.15.0-dev.1
# Experimental!

# &fras "input.txt"
&fras "example.txt"
°/$"_\n\n_"

# ≡(□⊜□⊸≠@\n°□)
# ≡(□°/$"_\n_"°□)
⍚°/$"_\n_"
∩°□:°⊟

ParseFirst ← ≡(◇⊜⋕⊸≠@|)
ParseSecond ← ≡(⍚⊜⋕⊸≠@,) ↘¯1 # last row is empty...

UpdateMap ← (
⊙⊃(⬚(□[])get|⊙∘):
insert:⍜(°□:)⊂
)

⊓($second ParseSecond|$first ∧(UpdateMap°⊟₂) :[] ParseFirst)

S ←
F ←
# map $ rules
🗺 ← ∧(UpdateMap°⊟₂) :[]

# $first ∧(UpdateMap°⊟₂) F $map []
# # ⍜(?⬚(□[])get5?)(?□?⊂?:3°□?) # pattern match failed, bugg?
# S

# - för varje i second
# - try get i first
# - för varje i first
# - jämför mot kvarvarande i second
# updates rules $ data
🗄 ← (
°/$"_\n\n_"
⍚°/$"_\n_"
∩°□:°⊟
⊓(≡(⍚⊜⋕⊸≠@,) ↘¯1|🗺≡(◇⊜⋕⊸≠@|))
)

# first: rules
# second: updates
# both: pages
# - för varje update
# - try get i rules
# - för varje i rules
# - jämför mot kvarvarande updates

S
# ↙2
$validrules ≡(
⇌°□
⇡⊸⧻
⊙¤
≡(↘
◇°⊂
°□⬚[]get:F
/∨∈:
)
/∨
-:1
# bool $ update rules
IsCorrectlyOrdered ← (
≡⌟◇(/∨◇∊: ⬚[]get ⊙: °⊂ ⇌) ⧅□
¬/∨
)
▽:S
/+≡(⊡⌊÷2⊸⧻°□)

# 6498, correct
# answer $ updates rules
🐪 ← (
▽⤚≡⌟◇IsCorrectlyOrdered
≡◇(⊡⌊÷2⊸⧻) # pick out the middle number
/+
)
┌─╴🧪
⍤⤙≍ 143 🐪 🗄 &fras "example.txt"
⍤⤙≍ 6498 🐪 🗄 &fras "input.txt"
└─╴

0 comments on commit 717e2be

Please sign in to comment.