~noelle/aoc-2021

3aac2c514668f9769f1c63a4bc5b8351679aaf6f — Noelle Leigh 2 years ago 0dee59a
11_1: WIP
5 files changed, 62 insertions(+), 0 deletions(-)

A 11/README.md
A 11/example.txt
A 11/input.txt
A 11/puzzle_1.py
A 11/small_example.txt
A 11/README.md => 11/README.md +3 -0
@@ 0,0 1,3 @@
Day 11: Dumbo Octopus

https://adventofcode.com/2021/day/11

A 11/example.txt => 11/example.txt +10 -0
@@ 0,0 1,10 @@
5483143223
2745854711
5264556173
6141336146
6357385478
4167524645
2176841721
6882881134
4846848554
5283751526

A 11/input.txt => 11/input.txt +10 -0
@@ 0,0 1,10 @@
8448854321
4447645251
6542573645
4725275268
6442514153
4515734868
5513676158
3257376185
2172424467
6775163586

A 11/puzzle_1.py => 11/puzzle_1.py +34 -0
@@ 0,0 1,34 @@
"""
Solution for AoC 2021 11 Puzzle 1

cat input.txt | python puzzle_1.py
"""
import sys

def print_octopi(octopi):
    for row in octopi:
        for col in row:
            sys.stdout.write(f"{col} ")
        sys.stdout.write("\n")

if __name__ == "__main__":
    octopi = list(
        map(
            lambda line: list(map(int, line)),
            sys.stdin.read().splitlines(),
        )
    )
    print_octopi(octopi)
    for step in range(1, 2 + 1):
        print("step", step)
        # Increment energy levels
        octopi = list(
            map(lambda row: list(map(lambda energy: energy + 1, row)), octopi)
        )
        # Look for flashes
        for row_index, row in enumerate(octopi):
            for col_index, energy in enumerate(row):
                if energy > 9:
                    octopi[row_index][col_index] = 0

        print_octopi(octopi)

A 11/small_example.txt => 11/small_example.txt +5 -0
@@ 0,0 1,5 @@
11111
19991
19191
19991
11111