part1 (4248B)
1--- Day 20: Jurassic Jigsaw --- 2 3The high-speed train leaves the forest and quickly carries you south. You can even see a desert in 4the distance! Since you have some spare time, you might as well see if there was anything 5interesting in the image the Mythical Information Bureau satellite captured. 6 7After decoding the satellite messages, you discover that the data actually contains many small 8images created by the satellite's [1m[37mcamera array[0m. The camera array consists of many 9cameras; rather than produce a single square image, they produce many smaller square image 10[1m[37mtiles[0m that need to be [1m[37mreassembled back into a single image[0m. 11 12Each camera in the camera array returns a single monochrome [1m[37mimage tile[0m with a random 13unique [1m[37mID number[0m. The tiles (your puzzle input) arrived in a random order. 14 15Worse yet, the camera array appears to be malfunctioning: each image tile has been [1m[37mrotated 16and flipped to a random orientation[0m. Your first task is to reassemble the original image by 17orienting the tiles so they fit together. 18 19To show how the tiles should be reassembled, each tile's image data includes a border that should 20line up exactly with its adjacent tiles. All tiles have this border, and the border lines up exactly 21when the tiles are both oriented correctly. Tiles at the edge of the image also have this border, 22but the outermost edges won't line up with any other tiles. 23 24For example, suppose you have the following nine tiles: 25 26Tile 2311: 27..##.#..#. 28##..#..... 29#...##..#. 30####.#...# 31##.##.###. 32##...#.### 33.#.#.#..## 34..#....#.. 35###...#.#. 36..###..### 37 38Tile 1951: 39#.##...##. 40#.####...# 41.....#..## 42#...###### 43.##.#....# 44.###.##### 45###.##.##. 46.###....#. 47..#.#..#.# 48#...##.#.. 49 50Tile 1171: 51####...##. 52#..##.#..# 53##.#..#.#. 54.###.####. 55..###.#### 56.##....##. 57.#...####. 58#.##.####. 59####..#... 60.....##... 61 62Tile 1427: 63###.##.#.. 64.#..#.##.. 65.#.##.#..# 66#.#.#.##.# 67....#...## 68...##..##. 69...#.##### 70.#.####.#. 71..#..###.# 72..##.#..#. 73 74Tile 1489: 75##.#.#.... 76..##...#.. 77.##..##... 78..#...#... 79#####...#. 80#..#.#.#.# 81...#.#.#.. 82##.#...##. 83..##.##.## 84###.##.#.. 85 86Tile 2473: 87#....####. 88#..#.##... 89#.##..#... 90######.#.# 91.#...#.#.# 92.######### 93.###.#..#. 94########.# 95##...##.#. 96..###.#.#. 97 98Tile 2971: 99..#.#....# 100#...###... 101#.#.###... 102##.##..#.. 103.#####..## 104.#..####.# 105#..#.#..#. 106..####.### 107..#.#.###. 108...#.#.#.# 109 110Tile 2729: 111...#.#.#.# 112####.#.... 113..#.#..... 114....#..#.# 115.##..##.#. 116.#.####... 117####.#.#.. 118##.####... 119##..#.##.. 120#.##...##. 121 122Tile 3079: 123#.#.#####. 124.#..###### 125..#....... 126######.... 127####.#..#. 128.#...#.##. 129#.#####.## 130..#.###... 131..#....... 132..#.###... 133 134By rotating, flipping, and rearranging them, you can find a square arrangement that causes all 135adjacent borders to line up: 136 137#...##.#.. ..###..### #.#.#####. 138..#.#..#.# ###...#.#. .#..###### 139.###....#. ..#....#.. ..#....... 140###.##.##. .#.#.#..## ######.... 141.###.##### ##...#.### ####.#..#. 142.##.#....# ##.##.###. .#...#.##. 143#...###### ####.#...# #.#####.## 144.....#..## #...##..#. ..#.###... 145#.####...# ##..#..... ..#....... 146#.##...##. ..##.#..#. ..#.###... 147 148#.##...##. ..##.#..#. ..#.###... 149##..#.##.. ..#..###.# ##.##....# 150##.####... .#.####.#. ..#.###..# 151####.#.#.. ...#.##### ###.#..### 152.#.####... ...##..##. .######.## 153.##..##.#. ....#...## #.#.#.#... 154....#..#.# #.#.#.##.# #.###.###. 155..#.#..... .#.##.#..# #.###.##.. 156####.#.... .#..#.##.. .######... 157...#.#.#.# ###.##.#.. .##...#### 158 159...#.#.#.# ###.##.#.. .##...#### 160..#.#.###. ..##.##.## #..#.##..# 161..####.### ##.#...##. .#.#..#.## 162#..#.#..#. ...#.#.#.. .####.###. 163.#..####.# #..#.#.#.# ####.###.. 164.#####..## #####...#. .##....##. 165##.##..#.. ..#...#... .####...#. 166#.#.###... .##..##... .####.##.# 167#...###... ..##...#.. ...#..#### 168..#.#....# ##.#.#.... ...##..... 169 170For reference, the IDs of the above tiles are: 171 172[1m[37m1951[0m 2311 [1m[37m3079[0m 1732729 1427 2473 174[1m[37m2971[0m 1489 [1m[37m1171[0m 175 176To check that you've assembled the image correctly, multiply the IDs of the four corner tiles 177together. If you do this with the assembled tiles from the example above, you get 1951 * 3079 * 2971 178* 1171 = [1m[37m20899048083289[0m. 179 180Assemble the tiles into an image. [1m[37mWhat do you get if you multiply together the IDs of the 181four corner tiles?[0m 182 183