# ---
# jupyter:
#   jupytext:
#     text_representation:
#       extension: .py
#       format_name: light
#       format_version: '1.5'
#       jupytext_version: 1.14.4
#   kernelspec:
#     display_name: Python [conda env:adventofcode]
#     language: python
#     name: conda-env-adventofcode-py
# ---

# # Day 6

# +
import csv
import numpy as np

instructions_list = []
with open('inputs/input6.txt', 'rt') as f_input:
    csv_reader = csv.reader(f_input, delimiter=' ')
    for line in csv_reader:
        c, d = tuple(map(int, line.pop().split(',')))
        line.pop()
        a, b = tuple(map(int, line.pop().split(',')))
        action = line.pop()
        instructions_list += [(action, a, b, c, d)]


# -

# ## Day 6.1

def lit(command):
    action = command[0]
    a, b, c, d = command[1:]
    if action == 'on':
        grid[a: c + 1, b: d + 1] = 1
    elif action == 'off':
        grid[a: c + 1, b: d + 1] = 0
    elif action == 'toggle':
        grid[a: c + 1, b: d + 1] = - grid[a: c + 1, b: d + 1] + 1


grid = np.zeros((1000, 1000))
for command in instructions_list:
    lit(command)
int(sum(sum(grid)))


# ## Day 6.2

def brightness_lit(command):
    action = command[0]
    a, b, c, d = command[1:]
    if action == 'on':
        grid[a: c + 1, b: d + 1] += 1
    elif action == 'off':
        grid[a: c + 1, b: d + 1] -= 1
    elif action == 'toggle':
        grid[a: c + 1, b: d + 1] += 2
    mask = grid < 0
    grid[mask] = 0


grid = np.zeros((1000, 1000))
for command in instructions_list:
    brightness_lit(command)
int(sum(sum(grid)))



StarcoderdataJupyterScriptsDedupFiltered