A repro for all my Advent of ode tasks
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 

57 lines
1.9 KiB

import sys
import os
import time
start = time.time()
grid = {}
brightness_grid = {}
for i in range(0, 1000):
for j in range (0, 1000):
grid[str(i)+','+str(j)] = False
brightness_grid[str(i)+','+str(j)] = 0
file = open('input.txt', 'r')
action = 0;
for line in file:
working_line = ""
if line.find("turn on") != -1:
action = 1
working_line = line.replace('turn on', '')
elif line.find("turn off") != -1:
action = 0
working_line = line.replace('turn off', '')
elif line.find("toggle") != -1:
action = 2
working_line = line.replace('toggle', '')
splits = working_line.split(' ')
start = splits[1].split(',')
end = splits[3].split(',')
for i in range(int(start[0]), int(end[0])+1):
for j in range(int(start[1]), int(end[1])+1):
if action == 1:
grid[str(i)+','+str(j)] = True
brightness_grid[str(i)+','+str(j)] += 1
elif action == 0:
grid[str(i)+','+str(j)] = False
brightness_grid[str(i)+','+str(j)] -= 1
if brightness_grid[str(i)+','+str(j)] < 0:
brightness_grid[str(i)+','+str(j)] = 0
elif action == 2:
if grid[str(i)+','+str(j)] == True:
grid[str(i)+','+str(j)] = False
elif grid[str(i)+','+str(j)] == False:
grid[str(i)+','+str(j)] = True
brightness_grid[str(i)+','+str(j)] += 2
lights_on = 0
lumens = 0
for i in range(0, 1000):
for j in range (0, 1000):
if grid[str(i)+','+str(j)] == True:
lights_on += 1
lumens += brightness_grid[str(i)+','+str(j)]
print("Santa left " + str(lights_on) + " lights on")
print("Santa is prodcing " + str(lumens) + " lumens of light")
print(time.time() - start)