mirror of
https://github.com/ershisan99/advent-of-code.git
synced 2025-12-18 04:59:24 +00:00
2015 day 6 refactored a bit
This commit is contained in:
@@ -1,15 +1,13 @@
|
||||
import os
|
||||
import re
|
||||
from collections import defaultdict
|
||||
|
||||
file_path = os.path.join(os.path.dirname(__file__), "./input.txt")
|
||||
# file_path = os.path.join(os.path.dirname(__file__), "./test-input.txt")
|
||||
input = open(file_path).read().strip()
|
||||
lines = input.split("\n")
|
||||
|
||||
lights = dict()
|
||||
for i in range(0, 1000):
|
||||
for j in range(0, 1000):
|
||||
lights[(i, j)] = 0
|
||||
lights = defaultdict(bool)
|
||||
for line in lines:
|
||||
match = re.findall(r"(.*?)(\d*,\d*) through (\d*,\d*)", line)
|
||||
if not match:
|
||||
@@ -21,14 +19,11 @@ for line in lines:
|
||||
for i in range(start[0], end[0] + 1):
|
||||
for j in range(start[1], end[1] + 1):
|
||||
if instruction == "turn on":
|
||||
lights[(i, j)] += 1
|
||||
lights[(i, j)] = True
|
||||
elif instruction == "turn off":
|
||||
if lights[(i, j)] == 0:
|
||||
continue
|
||||
else:
|
||||
lights[(i, j)] -= 1
|
||||
lights[(i, j)] = False
|
||||
else:
|
||||
lights[(i, j)] += 2
|
||||
lights[(i, j)] = not lights[(i, j)]
|
||||
count = 0
|
||||
for v in lights.values():
|
||||
count += v
|
||||
|
||||
Reference in New Issue
Block a user