Uiua
Took me a bit longer to get this one but still quite simple overall.
Spent quite some time on getting to know the try
and assert
operators better.
Run with example input here
# Get the indices matching the ascending/
# descending criteria
CheckAsc β β‘Β°β‘β(β£(βΈβ€.ββ.)β£(βΈβ€.βββ.)0)
# Get the indices matching the distance criteria
CheckDist β β‘Β°β‘β(β£(βΈβ€.β 1β:0)0Γββ₯β€1,3β΅β§-)
Split β β(β½β 1)β½,,
PartOne β (
&rs β &fo "input-2.txt"
β(β‘βββ @ .)β @\n.
CheckAsc.
β½
CheckDist
⧻β
)
PartTwo β (
&rs β &fo "input-2.txt"
β(β‘βββ @ .)β @\n.
CheckAsc.
Split
CheckDist.
Split
β(β)
⧻
:
β(β‘(β½:Β°β)βΒ€ββ:β 1β=.β‘⧻.)
β‘(⧻βCheckDistβ½CheckAsc.Β°β‘)
+⧻β΄β
)
&p "Day 2:"
&pf "Part 1: "
&p PartOne
&pf "Part 2: "
&p PartTwo