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

You are viewing a single thread.
View all comments
1 point
*

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
  1. Open the uiua pad with code here
  2. Replace the 0 in the first line with your solution for part two
  3. If necessary, change the name of the file containing your input
  4. Drag a file containing your input onto the pad to upload it and run the code
  5. 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:

permalink
report
reply

Advent Of Code

!advent_of_code@programming.dev

Create post

An unofficial home for the advent of code community on programming.dev!

Advent of Code is an annual Advent calendar of small programming puzzles for a variety of skill sets and skill levels that can be solved in any programming language you like.

AoC 2024

Solution Threads

M T W T F S S
1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25

Rules/Guidelines

  • Follow the programming.dev instance rules
  • Keep all content related to advent of code in some way
  • If what youre posting relates to a day, put in brackets the year and then day number in front of the post title (e.g. [2024 Day 10])
  • When an event is running, keep solutions in the solution megathread to avoid the community getting spammed with posts

Relevant Communities

Relevant Links

Credits

Icon base by Lorc under CC BY 3.0 with modifications to add a gradient

console.log('Hello World')

Community stats

  • 482

    Monthly active users

  • 108

    Posts

  • 1.1K

    Comments