Quantcast
Channel: Active questions tagged tiling - Code Golf Stack Exchange
Viewing all articles
Browse latest Browse all 35

AoCG2021 Day 25: Stitching maps together

0
0

Part of Advent of Code Golf 2021 event. See the linked meta post for details.

Related to AoC2020 Day 20, Part 1. (This day is a dreaded one for many of you, I know :P)

Obligatory final "but you're not Bubbler" explanation.


As the train carries you to the destination, you've got some spare time. You open the travel booklet for the vacation spot, and its map is divided into nine pieces... in random order and orientation. Apparently you got a brain teaser version of the booklet or something.

The map pieces are represented as a square grid of zeros and ones, and they are rotated and/or flipped in a random orientation. The four edges of each map piece are the clues: if two pieces have a common edge pattern (one of the four sides), two pieces are stitched together on that edge.

If two pieces look like this:

Piece 1:#..####...#.#.#.#.##....#Piece 2:#.###......#...##..#.##..

The right edge of Piece 1 and the top edge of Piece 2 match; you can flip Piece 2 with respect to its main diagonal, and then join the two horizontally.

You can't decide the orientation of the whole map yet, but at least you can assemble the 3x3 map and tell which piece goes to the center. This is the objective of this challenge.

The edge patterns are all distinct; for any given pattern that appears in the input, there are either exactly two pieces (for interior edges) or one (for outer edges) with that pattern. Also, every interior edge pattern is asymmetric, so that you can uniquely join the edges together (modulo orientation as a whole).

Input: A list of nine square grids of zeros and ones, representing the nine map pieces; you can choose any other two distinct values (numbers, chars, or strings) for zeros and ones.

Output: The square grid that corresponds to the center piece (any orientation is fine), or its index (0- or 1-based) in the input.

Standard rules apply. The shortest code in bytes wins.

Test case

Uses #s and .s.

Input:.###.######...#..##..##..#.###..#####...#.#..#...#.#...###..#....#...#.#.##...#..#....######...###.####.......#.###.....#.##.####.###....##...###.#..###.#.##...#.#.###...#.#..##..#..##.##....#....##.#.###.#...##.#.#.....####.#.#.#.###.#.....###.#.#.###.#......#.#.##....######.#..#.#..##...#.......#####..#.#.#..#####..#.##.Answer: 2nd-to-last piece (8th with 1-indexing)

Viewing all articles
Browse latest Browse all 35

Latest Images

Trending Articles





Latest Images