Day 14: Restroom Redoubt
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
Ok, so part one wasnât too hard, and since uiua also takes negative values for accessing arrays, I didnât even have to care about converting my modulus results (though I did later for part two).
Iâm a bit conflicted about the way I detected the quadrants the robots are in, or rather the way the creation of the mask-array happens. I basically made a 11x7 field of 0âs, then picked out each quadrant and added 1-4 respectively. Uiuaâs group (â
) function then takes care of putting all the robots in separate arrays for each quadrant. Simple.
For part two, I didnât even think long before I came here to see otherâs approaches. The idea to look for the first occurrence where no robotsâ positions overlapped was my starting point for what follows.
Example input stuff
Run with example input here
$ p=0,4 v=3,-3
$ p=6,3 v=-1,-3
$ p=10,3 v=-1,2
$ p=2,0 v=2,-1
$ p=0,0 v=1,3
$ p=3,0 v=-2,-2
$ p=7,6 v=-1,-3
$ p=3,0 v=-1,-2
$ p=9,3 v=2,3
$ p=7,3 v=-1,2
$ p=2,4 v=2,-3
$ p=9,5 v=-3,-3
.
PartOne â (
# &rs â &fo "input-14.txt"
â(âŻ2_2âregex"-?\\d+")â @\n.
âĄ(ââ”(âż11_7)+°âââĄâĂâââ)
âŻâ(âœĂ°â)7_11 0
âââ(ââĄââ
+âââĄââ+â)
âââ(ââĄââ
+âââĄââ+â)
/ĂâĄâ⧻ââĄ-ââž(âĄ:)â
)
PartTwo â (
# &rs â &fo "input-14.txt"
â(âŻ2_2âregex"-?\\d+")â @\n.
0 # number of seconds to start at
0_0
âą(âĄ(âĄ(ââ”(âż11_7)+°âââĄâĂ):)â
âż[11_7]âĄ+[11_7]
â+â
| â â(⧻âŽ)⧻.)
âââ
-â
)
&p "Day 14:"
&pf "Part 1: "
&p PartOne
&pf "Part 2: "
&p PartTwo
Now on to the more layered approach of how I got my solution.
In my case, thereâs two occasions of non-overlapping positions before the christmas tree appears.
I had some fun trying to get those frames and kept messing up with going back and forth between 7x11 vs 103x101 fields, often forgetting to adjust the modulus and other parts, so that was great.
In the end, I uploaded my input to the online uiua pad to make visualizing possible frames easier since uiua is able to output media if the arrays match a defined format.
Try it out yourself with your input
- Open the uiua pad with code here
- Replace the
0
in the first line with your solution for part two - If necessary, change the name of the file containing your input
- Drag a file containing your input onto the pad to upload it and run the code
- An image should be displayed
I used this code to find the occurrence of non-overlapping positions (running this locally):
&rs â &fo "input-14.txt"
â(âŻ2_2âregex"-?\\d+")â @\n.
0 # number of seconds to start at
0_0
âą(âĄ(âĄ(ââ”(âż101_103)+°âââĄâĂ):)â
âż[101_103]âĄ+[101_103]
â+â
| â â(⧻âŽ)⧻.)
âââ
-â
Whenever a new case was found, I put the result into the code in the online pad to check the generated image, and finally got this at the third try: