Day 6: Guard Gallivant
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
You are viewing a single thread.
View all comments 1 point
Uiua
Part one was simple enough. Part two nearly made me give up.
Part two has the most ugly and least performant code Iâve made in uiua so far but it gets the job done and thatâs all I care about for now.
Run with example input here
RotateClock â (
ââ(ââ)
â(ââ(âĄ0)(-â(⧻âĄ0.)+1))
â»ÂŻ1
)
RotateCounter â (
ââ(ââ)
â(â(âĄ0)(-â(⧻.)+1)â)
â»1
)
NewPos â (
ââ(ââĄ:)(-1+â(â@#)âââ.)â°â
â(âĄ1)â
)
MarkPath â (
RotateClock
âą( # replace characters up til next '#'
â(ââ(âââĄ:)(â(â)(âœ:@^⧻)â@#.)â°â
NewPos
)
RotateCounter
| â
(â 0âĄ0))
ââ
)
PartOne â (
&rs â &fo "input-6.txt"
âââ @\n.
# maybe make compatible with
# non-up facing inputs
ââ=@^.
[0 1 2 3]
MarkPath
&fwa "test.txt" json.
/+/+=@^
)
PartTwo â (
&rs â &fo "input-6.txt"
âââ @\n.
# maybe make compatible with
# non-up facing inputs
ââ=@^.
[0 1 2 3]
âĄMarkPath
â::
# rotate the field to match the intital state
ââ(
â(â=@#)
âą(ââ|ÂŹââ=@#)
ââ
)
ââ(â=@^.)
âââ€â©Â€
â(ââ(ââĄâ
@#)
RotateClock
âNewPos
€¯1_¯1_¯1
âą(ââĄ(ââą)
â
â(RotateCounter
âNewPos
)
| =1+â(ââ1â)âĄâ
(â 129âĄ2)â(ââą))
# 129 = length of input array. Hardcoded because
# the condition block doesn't seem to get the
# input array passed to it so the length can't
# be read dynamically
â(ââą)
â
ââ
)
/+â
)
&p "Day 6:"
&pf "Part 1: "
&p PartOne
&pf "Part 2: "
&p PartTwo