Day 18 - Advent of Code 2016
Working solution for the day 18 puzzles.
Parts One and Two
""" day_18_01_02.py """
# usage: python3 day_18_01_02.py 40 < input
# usage: python3 day_18_01_02.py 400000 < input
import sys
situations = [['^', '.', '.'], ['^', '^', '.'], ['.', '.', '^'], ['.', '^', '^']]
rows = int(sys.argv[1])
row = ['.'] + list(input()) + ['.']
count = row.count('.')
for _ in range(rows - 1):
prev = row
row = ['.' for _ in prev]
for i in range(1, len(prev)):
if prev[i - 1:i + 2] in situations:
row[i] = '^'
count += row.count('.')
print(count - 2 * rows)