# ---
# jupyter:
#   jupytext:
#     text_representation:
#       extension: .py
#       format_name: light
#       format_version: '1.5'
#       jupytext_version: 1.14.4
#   kernelspec:
#     display_name: Python 3
#     language: python
#     name: python3
# ---

from utils import Utils, AOC
from session import SESSION
import numpy as np

# + pycharm={"name": "#%%\n"}
aoc = AOC(session=SESSION)

# + pycharm={"name": "#%%\n"}
aoc.verify_session()

# + pycharm={"name": "#%%\n"}
aoc.get_file(year=2021, day=4).analyse().head()

# + pycharm={"name": "#%%\n"}
numbers, *tables = aoc.data
marks = np.array(tables)
marks.fill(1)


# + pycharm={"name": "#%%\n"}
def mark(number):
    for i in range(len(tables)):
        for loc in zip(*np.where(tables[i]==number)):
            print(loc)
            marks[i][loc] = 0
            tables[i][loc] = 0


# + pycharm={"name": "#%%\n"}
def check():
    for i in range(len(tables)):
        if min(min(marks[i].sum(axis=0)), min(marks[i].sum(axis=1))) == 0:
            return i


# + pycharm={"name": "#%%\n"}
for n in numbers:
    mark(n)
    c = check()
    if c is not None:
        #print(n, c)
        break

# + pycharm={"name": "#%%\n"}
tables[c].sum() * n


# + pycharm={"name": "#%%\n"}
def check2():
    v = set()
    for i in range(len(tables)):
        if min(min(marks[i].sum(axis=0)), min(marks[i].sum(axis=1))) == 0:
            v.add(i)
    if len(v) == len(tables):
        return set(range(len(tables))).difference(v)


# + pycharm={"name": "#%%\n"}
for n in numbers:
    mark(n)
    c = check2()
    if c is not None:
        #print(n, c)
        break

# + pycharm={"name": "#%%\n"}
# < 15895
# = 8224

# + pycharm={"name": "#%%\n"}
tables[83].sum() * n

# + pycharm={"name": "#%%\n"}
tables[83]

StarcoderdataJupyterScriptsDedupFiltered