aoc-2020-zig

Advent of Code 2020 Solutions in Zig
git clone https://git.sinitax.com/sinitax/aoc-2020-zig
Log | Files | Refs | README | sfeed.txt

part1 (2949B)


      1--- Day 24: Lobby Layout ---
      2
      3Your raft makes it to the tropical island; it turns out that the small crab was an excellent
      4navigator. You make your way to the resort.
      5
      6As you enter the lobby, you discover a small problem: the floor is being renovated. You can't even
      7reach the check-in desk until they've finished installing the new tile floor.
      8
      9The tiles are all hexagonal; they need to be arranged in a hex grid with a very
     10specific color pattern. Not in the mood to wait, you offer to help figure out the pattern.
     11
     12The tiles are all white on one side and black on the other. They start
     13with the white side facing up. The lobby is large enough to fit whatever pattern might need to
     14appear there.
     15
     16A member of the renovation crew gives you a list of the tiles that need to be flipped
     17over (your puzzle input). Each line in the list identifies a single tile that needs to be
     18flipped by giving a series of steps starting from a reference tile in the very center
     19of the room. (Every line starts from the same reference tile.)
     20
     21Because the tiles are hexagonal, every tile has six neighbors: east, southeast,
     22southwest, west, northwest, and northeast. These directions are given in your list, respectively, as
     23e, se, sw, w, nw, and ne. A tile is identified by a series of these directions with no
     24delimiters; for example, esenee identifies the tile you land on if you start at the reference
     25tile and then move one tile east, one tile southeast, one tile northeast, and one tile east.
     26
     27Each time a tile is identified, it flips from white to black or from black to white. Tiles might be
     28flipped more than once. For example, a line like esew flips a tile immediately adjacent to the
     29reference tile, and a line like nwwswee flips the reference tile itself.
     30
     31Here is a larger example:
     32
     33sesenwnenenewseeswwswswwnenewsewsw
     34neeenesenwnwwswnenewnwwsewnenwseswesw
     35seswneswswsenwwnwse
     36nwnwneseeswswnenewneswwnewseswneseene
     37swweswneswnenwsewnwneneseenw
     38eesenwseswswnenwswnwnwsewwnwsene
     39sewnenenenesenwsewnenwwwse
     40wenwwweseeeweswwwnwwe
     41wsweesenenewnwwnwsenewsenwwsesesenwne
     42neeswseenwwswnwswswnw
     43nenwswwsewswnenenewsenwsenwnesesenew
     44enewnwewneswsewnwswenweswnenwsenwsw
     45sweneswneswneneenwnewenewwneswswnese
     46swwesenesewenwneswnwwneseswwne
     47enesenwswwswneneswsenwnewswseenwsese
     48wnwnesenesenenwwnenwsewesewsesesew
     49nenewswnwewswnenesenwnesewesw
     50eneswnwswnwsenenwnwnwwseeswneewsenese
     51neswnwewnwnwseenwseesewsenwsweewe
     52wseweeenwnesenwwwswnew
     53
     54In the above example, 10 tiles are flipped once (to black), and 5 more are flipped twice (to black,
     55then back to white). After all of these instructions have been followed, a total of 10
     56tiles are black.
     57
     58Go through the renovation crew's list and determine which tiles they need to flip. After all of the
     59instructions have been followed, how many tiles are left with the black side up?
     60
     61