VP 30: Tiles (15 pts + 60 extra)

What You Need

Any computer with Python 3. You can also use an online Python environment, such as https://colab.research.google.com

Task

The input is a set of square image tiles that need to be reassembled back into a single image.

Each tile has an unique ID number. Each tile is a 10x10 grid of characters.

Each image tile has been rotated and flipped to a random orientation. Your first task is to reassemble the original image by orienting the tiles so they fit together.

To show how the tiles should be reassembled, each tile's image data includes a border that should line up exactly with its adjacent tiles. All tiles have this border, and the border lines up exactly when the tiles are both oriented correctly. Tiles at the edge of the image also have this border, but the outermost edges won't line up with any other tiles.

For example, suppose you have the following nine tiles:

Tile 2311:
..##.#..#.
##..#.....
#...##..#.
####.#...#
##.##.###.
##...#.###
.#.#.#..##
..#....#..
###...#.#.
..###..###

Tile 1951:
#.##...##.
#.####...#
.....#..##
#...######
.##.#....#
.###.#####
###.##.##.
.###....#.
..#.#..#.#
#...##.#..

Tile 1171:
####...##.
#..##.#..#
##.#..#.#.
.###.####.
..###.####
.##....##.
.#...####.
#.##.####.
####..#...
.....##...

Tile 1427:
###.##.#..
.#..#.##..
.#.##.#..#
#.#.#.##.#
....#...##
...##..##.
...#.#####
.#.####.#.
..#..###.#
..##.#..#.

Tile 1489:
##.#.#....
..##...#..
.##..##...
..#...#...
#####...#.
#..#.#.#.#
...#.#.#..
##.#...##.
..##.##.##
###.##.#..

Tile 2473:
#....####.
#..#.##...
#.##..#...
######.#.#
.#...#.#.#
.#########
.###.#..#.
########.#
##...##.#.
..###.#.#.

Tile 2971:
..#.#....#
#...###...
#.#.###...
##.##..#..
.#####..##
.#..####.#
#..#.#..#.
..####.###
..#.#.###.
...#.#.#.#

Tile 2729:
...#.#.#.#
####.#....
..#.#.....
....#..#.#
.##..##.#.
.#.####...
####.#.#..
##.####...
##..#.##..
#.##...##.

Tile 3079:
#.#.#####.
.#..######
..#.......
######....
####.#..#.
.#...#.##.
#.#####.##
..#.###...
..#.......
..#.###...

Counting Hash Marks

Count the hash marks(#) in all the tiles. For the nine example tiles above, there are a total of 448 hash marks.

VP 30.1: Counting Hash Marks (5 pts)

Use this data:
https://samsclass.info/COMSC132/proj/VP30

Count the hash marks(#) in all the images. That total number is the flag.

Constructing Edge Numbers

Consider the first tile, Tile 2311:
..##.#..#.
##..#.....
#...##..#.
####.#...#
##.##.###.
##...#.###
.#.#.#..##
..#....#..
###...#.#.
..###..###
Read the top edge as a binary number, treating a period as zero and a hashmark as 1. You get:
Top =    ..##.#..#.
         0011010010 = 210
Now do the same for the right edge, the bottom, and the left edge, reading in a clockwise direction. You get:
Right =  ...#.##..#
         0001011001 = 89

Bottom = ###..###.. 
         1110011100 = 924

Left =   .#..#####.
         0100111110 = 318	
Now turn the tile over, rotating it about a vertical axis, and construct the new edge numbers, as shown below:
Flipped: Tile: 2311

.#..#.##..
.....#..##
.#..##...#
#...#.####
.###.##.##
###.#...##
##..#.#.#.
..#....#..
.#.#...###
###..###..

Edges: [300, 498, 231, 616]
There are 8 edge numbers per tile.

The sample data above contains nine tiles, so there are 72 edges.

Adding all those edges together results in 29496.

VP 30.2: Edge Numbers (10 pts)

Use this data:
https://samsclass.info/COMSC132/proj/VP30
Find the total of all the edge numbers, as explained above.

That's the flag.

Matching the Tiles

Placing the tiles in the order they appeared in the original data, and labelling all the edges with their numbers, produces the grid below.

Asterisks mark the edge numbers with matches in other tiles.

-------------------------------------------------------------------
|     Tile: 2311      |     Tile: 1951      |     Tile: 1171      |
|                     |                     |                     |
|    (210*, 300*)     |    (710*, 397*)     |    (966*, 399*)     |
|(318*,         ( 89*,|(587 ,         (498*,|(391 ,         (288*,|
| 616*)          498*)| 318*)          841 )|  18*)          902 )|
|    (924 , 231 )     |    (177 , 564 )     |    ( 96 ,  24 )     |
-------------------------------------------------------------------
|     Tile: 1427      |     Tile: 1489      |     Tile: 2473      |
|                     |                     |                     |
|    (948*, 183*)     |    (848 ,  43 )     |    (542 , 481 )     |
|(  9*,         (234*,|(689*,         ( 18*,|(399*,         (116*,|
| 348*)          576*)| 288*)          565*)| 184*)          966*)|
|    (300*, 210*)     |    (183*, 948*)     |    (348*, 234*)     |
-------------------------------------------------------------------
|     Tile: 2971      |     Tile: 2729      |     Tile: 3079      |
|                     |                     |                     |
|    (161 , 532 )     |    ( 85*, 680*)     |    (702 , 501 )     |
|( 78 ,         (565*,|(962 ,         (576*,|( 89*,         (264 ,|
| 689*)          456 )|   9*)          271 )|  66 )          616*)|
|    (680*,  85*)     |    (397*, 710*)     |    (116*, 184*)     |
-------------------------------------------------------------------

Matching Edges

For each tile, count how many edge numbers match edge numbers from other tiles.

There are three possibilities:

For the sample data above, here are the results:
Corners: [1951, 1171, 2971, 3079]
Sides: [2311, 1489, 2473, 2729]
Insides: [1427]

VP 30.3: Corners (10 pts extra)

Use this data:
https://samsclass.info/COMSC132/proj/VP30
Find the four corner tiles. Multiply their IDs together.

That's the flag.

Assembling the Grid

Put a corner in the data at the top left.

Rotate it as needed to put the outside edges on the outside.

Then fill in the grid with the other tiles.

By rotating, flipping, and rearranging them, you can find a square arrangement that causes all adjacent borders to line up, as shown below. Your solution may have the entire grid rotated or flipped, but that's OK as long as the tile edges match.

#...##.#.. ..###..### #.#.#####.
..#.#..#.# ###...#.#. .#..######
.###....#. ..#....#.. ..#.......
###.##.##. .#.#.#..## ######....
.###.##### ##...#.### ####.#..#.
.##.#....# ##.##.###. .#...#.##.
#...###### ####.#...# #.#####.##
.....#..## #...##..#. ..#.###...
#.####...# ##..#..... ..#.......
#.##...##. ..##.#..#. ..#.###...

#.##...##. ..##.#..#. ..#.###...
##..#.##.. ..#..###.# ##.##....#
##.####... .#.####.#. ..#.###..#
####.#.#.. ...#.##### ###.#..###
.#.####... ...##..##. .######.##
.##..##.#. ....#...## #.#.#.#...
....#..#.# #.#.#.##.# #.###.###.
..#.#..... .#.##.#..# #.###.##..
####.#.... .#..#.##.. .######...
...#.#.#.# ###.##.#.. .##...####

...#.#.#.# ###.##.#.. .##...####
..#.#.###. ..##.##.## #..#.##..#
..####.### ##.#...##. .#.#..#.##
#..#.#..#. ...#.#.#.. .####.###.
.#..####.# #..#.#.#.# ####.###..
.#####..## #####...#. .##....##.
##.##..#.. ..#...#... .####...#.
#.#.###... .##..##... .####.##.#
#...###... ..##...#.. ...#..####
..#.#....# ##.#.#.... ...##.....
For reference, the IDs of the above tiles are:
1951    2311    3079
2729    1427    2473
2971    1489    1171
To find the flag, add the tile ID numbers along the main diagonals, like this:
1951 + 1427 +  1171 + 3079 + 2971 = 10599    

VP 30.4: Assembling the Grid (50 pts extra)

Use this data:
https://samsclass.info/COMSC132/proj/VP30
There are 144 tiles. Assemble them into a 12x12 grid, with all the tile edges matching.

Add the tile ID numbers along the main diagonals, as explained above.

That's the flag.

Source

Adapted from the Advent of Code.

Posted 10-3-24
Video added 10-9-24
Flag VP 30.2 verified 10-21-24