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

part2 (3335B)


      1--- Part Two ---
      2
      3Now, you're ready to check the image for sea monsters.
      4
      5The borders of each tile are not part of the actual image; start by removing them.
      6
      7In the example above, the tiles become:
      8
      9.#.#..#. ##...#.# #..#####
     10###....# .#....#. .#......
     11##.##.## #.#.#..# #####...
     12###.#### #...#.## ###.#..#
     13##.#.... #.##.### #...#.##
     14...##### ###.#... .#####.#
     15....#..# ...##..# .#.###..
     16.####... #..#.... .#......
     17
     18#..#.##. .#..###. #.##....
     19#.####.. #.####.# .#.###..
     20###.#.#. ..#.#### ##.#..##
     21#.####.. ..##..## ######.#
     22##..##.# ...#...# .#.#.#..
     23...#..#. .#.#.##. .###.###
     24.#.#.... #.##.#.. .###.##.
     25###.#... #..#.##. ######..
     26
     27.#.#.### .##.##.# ..#.##..
     28.####.## #.#...## #.#..#.#
     29..#.#..# ..#.#.#. ####.###
     30#..####. ..#.#.#. ###.###.
     31#####..# ####...# ##....##
     32#.##..#. .#...#.. ####...#
     33.#.###.. ##..##.. ####.##.
     34...###.. .##...#. ..#..###
     35
     36Remove the gaps to form the actual image:
     37
     38.#.#..#.##...#.##..#####
     39###....#.#....#..#......
     40##.##.###.#.#..######...
     41###.#####...#.#####.#..#
     42##.#....#.##.####...#.##
     43...########.#....#####.#
     44....#..#...##..#.#.###..
     45.####...#..#.....#......
     46#..#.##..#..###.#.##....
     47#.####..#.####.#.#.###..
     48###.#.#...#.######.#..##
     49#.####....##..########.#
     50##..##.#...#...#.#.#.#..
     51...#..#..#.#.##..###.###
     52.#.#....#.##.#...###.##.
     53###.#...#..#.##.######..
     54.#.#.###.##.##.#..#.##..
     55.####.###.#...###.#..#.#
     56..#.#..#..#.#.#.####.###
     57#..####...#.#.#.###.###.
     58#####..#####...###....##
     59#.##..#..#...#..####...#
     60.#.###..##..##..####.##.
     61...###...##...#...#..###
     62
     63Now, you're ready to search for sea monsters! Because your image is monochrome, a sea monster will
     64look like this:
     65
     66                  # 
     67#    ##    ##    ###
     68 #  #  #  #  #  #   
     69
     70When looking for this pattern in the image, the spaces can be anything; only the # need
     71to match. Also, you might need to rotate or flip your image before it's oriented correctly to find
     72sea monsters. In the above image, after flipping and rotating it to the appropriate
     73orientation, there are two sea monsters (marked with O):
     74
     75.####...#####..#...###..
     76#####..#..#.#.####..#.#.
     77.#.#...#.###...#.##.O#..
     78
     79#.O.##.OO#.#.OO.##.OOO##
     80
     81..#O.#O#.O##O..O.#O##.##
     82...#.#..##.##...#..#..##
     83#.##.#..#.#..#..##.#.#..
     84.###.##.....#...###.#...
     85#.####.#.#....##.#..#.#.
     86##...#..#....#..#...####
     87..#.##...###..#.#####..#
     88....#.##.#.#####....#...
     89..##.##.###.....#.##..#.
     90#...#...###..####....##.
     91.#.##...#.##.#.#.###...#
     92#.###.#..####...##..#...
     93#.###...#.##...#.##O###.
     94
     95.O##.#OO.###OO##..OOO##.
     96
     97..O#.O..O..O.#O##O##.###
     98#.#..##.########..#..##.
     99#.#####..#.#...##..#....
    100#....##..#.#########..##
    101#...#.....#..##...###.##
    102#..###....##.#...##.##.#
    103
    104Determine how rough the waters are in the sea monsters' habitat by counting the number of # that are
    105not part of a sea monster. In the above example, the habitat's water roughness is
    106273.
    107
    108How many # are not part of a sea monster?
    109
    110