this post was submitted on 21 Dec 2023
12 points (92.9% liked)

Advent Of Code

21 readers
1 users here now

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 2023

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

Relevant Communities

Relevant Links

Credits

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

console.log('Hello World')

founded 1 year ago
MODERATORS
 

Day 21: Step

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 comment's thread
view the rest of the comments
[–] [email protected] 1 points 8 months ago* (last edited 8 months ago)

Nim

My part 2 solution assumes the input has an unimpeded shortest path from the center of each garden section to its corner, and to the center of its neighbor. The possible destinations will form a diamond pattern, with "radius" equal to the number of steps. I broke down the possible section permutations:

  • Sections that are completely within the interior of the diamond

    • Even number of sections away from the starting section
    • Odd number of sections away from the starting section
  • Sections containing the points of the diamond

  • Depending on the number of steps, there may be sections adjacent to the point sections, that have two corners outside of the diamond

  • Edge sections. These will form a zig-zag pattern to cover the diamond boundary.

    • "Near" edge sections. These are the parts of the zig-zag nearer to the center of the diamond.
    • "Far" edge sections. These won't occur if the edge of the diamond passes perfectly through the corners of the near edge sections.

I determined how many of each of these should be present based on the number of steps, used my code from part 1 to get a destination count for each type, and then added them all up.