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

  • cacheson@kbin.social
    link
    fedilink
    arrow-up
    1
    ·
    edit-2
    10 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.