[Python/2015] Move solutions into .py files
This commit is contained in:
parent
8c2be5fb77
commit
94dd3ae399
52 changed files with 996 additions and 3314 deletions
30
Python/2015/06.py
Normal file
30
Python/2015/06.py
Normal file
|
@ -0,0 +1,30 @@
|
|||
from lib import *
|
||||
|
||||
input = read_input(2015, 6)
|
||||
|
||||
|
||||
def parse_instructions(instructions):
|
||||
out = []
|
||||
|
||||
for line in instructions:
|
||||
inst, *coords = re.match(r"^([a-z ]+) (\d+),(\d+) through (\d+),(\d+)$", line).groups()
|
||||
|
||||
out.append((["turn off", "turn on", "toggle"].index(inst), *map(int, coords)))
|
||||
|
||||
return out
|
||||
|
||||
|
||||
lights = [[0 for _ in range(1000)] for _ in range(1000)]
|
||||
for inst, x1, y1, x2, y2 in parse_instructions(input.splitlines()):
|
||||
for y in range(y1, y2 + 1):
|
||||
for x in range(x1, x2 + 1):
|
||||
lights[y][x] = 1 - lights[y][x] if inst == 2 else inst
|
||||
print(sum(map(sum, lights)))
|
||||
|
||||
|
||||
lights = [[0 for _ in range(1000)] for _ in range(1000)]
|
||||
for inst, x1, y1, x2, y2 in parse_instructions(input.splitlines()):
|
||||
for y in range(y1, y2 + 1):
|
||||
for x in range(x1, x2 + 1):
|
||||
lights[y][x] = max(0, lights[y][x] + (inst or -1))
|
||||
print(sum(map(sum, lights)))
|
Loading…
Add table
Add a link
Reference in a new issue