part1 (2769B)
1--- Day 11: Seating System --- 2 3Your plane lands with plenty of time to spare. The final leg of your journey is a ferry that goes 4directly to the tropical island where you can finally start your vacation. As you reach the waiting 5area to board the ferry, you realize you're so early, nobody else has even arrived yet! 6 7By modeling the process people use to choose (or abandon) their seat in the waiting area, you're 8pretty sure you can predict the best place to sit. You make a quick map of the seat layout (your 9puzzle input). 10 11The seat layout fits neatly on a grid. Each position is either floor (.), an empty seat (L), or an 12occupied seat (#). For example, the initial seat layout might look like this: 13 14L.LL.LL.LL LLLLLLL.LL L.L.L..L.. LLLL.LL.LL L.LL.LL.LL L.LLLLL.LL ..L.L..... LLLLLLLLLL L.LLLLLL.L 15L.LLLLL.LL 16 17Now, you just need to model the people who will be arriving shortly. Fortunately, people are 18entirely predictable and always follow a simple set of rules. All decisions are based on the 19[1m[37mnumber of occupied seats[0m adjacent to a given seat (one of the eight positions 20immediately up, down, left, right, or diagonal from the seat). The following rules are applied to 21every seat simultaneously: 22 23- If a seat is [1m[37mempty[0m (L) and there are [1m[37mno[0m occupied seats adjacent to it, 24the seat becomes [1m[37moccupied[0m. - If a seat is [1m[37moccupied[0m (#) and [1m[37mfour 25or more[0m seats adjacent to it are also occupied, the seat becomes [1m[37mempty[0m. - 26Otherwise, the seat's state does not change. 27 28Floor (.) never changes; seats don't move, and nobody sits on the floor. 29 30After one round of these rules, every seat in the example layout becomes occupied: 31 32#.##.##.## #######.## #.#.#..#.. ####.##.## #.##.##.## #.#####.## ..#.#..... ########## #.######.# 33#.#####.## 34 35After a second round, the seats with four or more occupied adjacent seats become empty again: 36 37#.LL.L#.## #LLLLLL.L# L.L.L..L.. #LLL.LL.L# #.LL.LL.LL #.LLLL#.## ..L.L..... #LLLLLLLL# #.LLLLLL.L 38#.#LLLL.## 39 40This process continues for three more rounds: 41 42#.##.L#.## #L###LL.L# L.#.#..#.. #L##.##.L# #.##.LL.LL #.###L#.## ..#.#..... #L######L# #.LL###L.L 43#.#L###.## 44 45#.#L.L#.## #LLL#LL.L# L.L.L..#.. #LLL.##.L# #.LL.LL.LL #.LL#L#.## ..L.L..... #L#LLLL#L# #.LLLLLL.L 46#.#L#L#.## 47 48#.#L.L#.## #LLL#LL.L# L.#.L..#.. #L##.##.L# #.#L.LL.LL #.#L#L#.## ..L.L..... #L#L##L#L# #.LLLLLL.L 49#.#L#L#.## 50 51At this point, something interesting happens: the chaos stabilizes and further applications of these 52rules cause no seats to change state! Once people stop moving around, you count [1m[37m37[0m 53occupied seats. 54 55Simulate your seating area by applying the seating rules repeatedly until no seats change state. 56[1m[37mHow many seats end up occupied?[0m 57 58