Day 7: Bridge Repair
Megathread guidelines
- Keep top level comments as only solutions, if you want to say something other than a solution put it in a new post. (replies to comments can be whatever)
- You can send code in code blocks by using three backticks, the code, and then three backticks or use something such as https://topaz.github.io/paste/ if you prefer sending it through a URL
FAQ
- What is this?: Here is a post with a large amount of details: https://programming.dev/post/6637268
- Where do I participate?: https://adventofcode.com/
- Is there a leaderboard for the community?: We have a programming.dev leaderboard with the info on how to join in this post: https://programming.dev/post/6631465
Uiua
Credits to @mykl@lemmy.world for the approach of using reduce
and also how to split the input by multiple characters.
I can happily say that I learned quite a bit today, even though the first part made me frustrated enough that I went searching for other approaches ^^
Part two just needed a simple modification. Changing how the input is parsed and passed to the adapted function took longer than changing the function itself actually.
Run with example input here
PartOne β (
&rs β &fo "input-7.txt"
ββ‘β @\n.
β‘β(ββ‘β @:.)
β‘ββ‘β0
β‘β(Β°β‘β‘1)(βββ @ .)
β(β‘0β)
# own attempt, produces a too low number
# β‘(:β©Β°β‘Β°β
# β£(β€.β‘β£(1β€.(β€/Γ)β€.(β₯/+),,)0
# βΒ€β―β‘βΏ:2-1βΈβ§»
# β(β₯(ββ(β(β2))(⨬+ΓβΒ°ββ‘0)
# β1
# )⧻.
# β€.=0⧻.
# )
# βββ
# )0)
# reduce approach found on the programming.dev AoC community by mykl@lemmy.world
β‘(β(β/(β΄β[β(+|Γ)]))β‘0:Β°β)
Β°β‘/+β½
)
PartTwo β (
&rs β &fo "input-7.txt"
β(β‘ββΒ¬β": ".)β @\n.
ββ‘ββ’
β‘β(β/(β΄β[β‘ββ(+|Γ|β$"__")]):Β°β)
Β°β‘/+β½
)
&p "Day 7:"
&pf "Part 1: "
&p PartOne
&pf "Part 2: "
&p PartTwo