From 8fa85c75cd5fc3a3ae532094d51db13d154283f0 Mon Sep 17 00:00:00 2001 From: kwout Date: Sun, 4 Sep 2022 13:15:16 -0400 Subject: [PATCH] add readme, add sample data for day1 day2, completed solution for day4a --- 2021/day4/4a.py | 39 +++++++++++++++++++++++++++++++++++++++ README.md | 13 +++++++++++++ 2 files changed, 52 insertions(+) create mode 100644 2021/day4/4a.py create mode 100644 README.md diff --git a/2021/day4/4a.py b/2021/day4/4a.py new file mode 100644 index 0000000..0a04111 --- /dev/null +++ b/2021/day4/4a.py @@ -0,0 +1,39 @@ +lines = open("input.txt", 'r').read().splitlines() +draw = [int(i) for i in lines[0].split(",")] +boards = [] +for s in range(2, len(lines),6): + boards.append([[int(j) for j in lines[i].split()] for i in range(s,s+5)]) + +earliestWin = len(draw) +winBoard = 0 + +for b in range(0, len(boards)): + for i in range(0, 5): + latest = 0 + for j in range(0, 5): + if boards[b][i][j] not in draw: + break + index = draw.index(boards[b][i][j]) + if index > latest: + latest = index + if latest < earliestWin and latest != 0: + earliestWin = latest + winBoard = int(b) + latest = 0 + for j in range(0, 5): + if boards[b][j][i] not in draw: + break + index = draw.index(boards[b][j][i]) + if index > latest: + latest = index + if latest < earliestWin and latest != 0: + earliestWin = latest + winBoard = b + +summa = 0 +for row in boards[winBoard]: + for n in row: + if n not in draw[:earliestWin+1]: + summa += n + +print(draw[earliestWin]*summa) diff --git a/README.md b/README.md new file mode 100644 index 0000000..790125e --- /dev/null +++ b/README.md @@ -0,0 +1,13 @@ +my solutions for the [Advent of Code](https://adventofcode.com/) + +in progress: +2021 (python) + +planned: +2022 (swift) +2020 (rust?) +2019 +2018 +2017 +2016 +2015