adventOfCode/challenges/2020/24-lobbyLayout
AKU 25f4d9d658
Add 2020 solutions
Signed-off-by: AKU <tom@tdpain.net>
2021-11-27 20:33:25 +00:00
..
python Add 2020 solutions 2021-11-27 20:33:25 +00:00
info.json Add 2020 solutions 2021-11-27 20:33:25 +00:00
README.md Add 2020 solutions 2021-11-27 20:33:25 +00:00

Day 24: Lobby Layout

More cellular automata! Just this time, weird. Perhaps even weirder than day 17. Hexagonal cells broke my brain a pretty substantial amount.

This StackOverflow answer proved pretty crucial to me ending up solving the challenge. To summarise:

We can represent our flooring using a typical 2D array, provided we visualise it with each line offset by a constant amount from the previous like so:

(0,0) (0,1) (0,2) (0,3) (0,4)

   (1,0) (1,1) (1,2) (1,3) (1,4)

      (2,0) (2,1) (2,2) (2,3) (2,4)

         (3,0) (3,1) (3,2) (3,3) (3,4)

The six neighbours to a given cell form what I believe called a slanted neighbourhood.

Using this, we can find a series of vectors that represent e, se, sw, w, nw, and ne directions from a specific tile.

(r, s) current tile

(r-1, s) nw
(r-1, s+1) ne
(r, s-1) w
(r, s+1) e
(r+1, s-1) sw
(r+1, s) se

From here onwards, it's pretty simple to solve the rest of the challenge.

Script output
 python .\python\ ft
AoC 2020: day 24 - Lobby Layout
Python 3.8.5

Test cases
1.1 pass in 0.0004611015319824219 seconds
2.1 pass in 0.6723911762237549 seconds

Answers
Part 1: 497 in 0.004002571105957031 seconds
Part 2: 4156 in 1.6635417938232422 seconds