From 8eded1bfe865f3248a7931caf1c86c7b97aa495e Mon Sep 17 00:00:00 2001 From: starnakin Date: Sun, 3 Dec 2023 07:29:32 +0100 Subject: [PATCH] add: part1 --- 2023/day03/example1.txt | 10 ++++++++++ 2023/day03/src/part1.py | 43 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 53 insertions(+) create mode 100644 2023/day03/example1.txt create mode 100644 2023/day03/src/part1.py diff --git a/2023/day03/example1.txt b/2023/day03/example1.txt new file mode 100644 index 0000000..624ea4f --- /dev/null +++ b/2023/day03/example1.txt @@ -0,0 +1,10 @@ +467..114.. +...*...... +..35..633. +......#... +617*...... +.....+.58. +..592..... +......755. +...$.*.... +.664.598.. \ No newline at end of file diff --git a/2023/day03/src/part1.py b/2023/day03/src/part1.py new file mode 100644 index 0000000..3e38559 --- /dev/null +++ b/2023/day03/src/part1.py @@ -0,0 +1,43 @@ +text: str = open("input.txt", "r").read() + +value: int = 0; + +def get_symbol_around(list:[str], pos: tuple, length: int): + start = [0,0] + end = [0,0] + + start[0] = pos[0] + start[1] = pos[1] + start[0] -= (start[0] != 0) + start[1] -= (start[1] != 0) + end[0] = pos[0] + end[1] = pos[1] + end[0] += length + end[0] += end[0] < len(list[pos[1]]) + end[1] += end[1] < len(list) + bozo = list[start[1]:end[1] + 1] + for y in bozo: + bozo2 = y[start[0]:end[0]] + print(bozo2) + for x in bozo2: + if (not x.isdigit() and not x == "."): + print() + return 1 + print() + return 0 + +lst = text.split("\n") +end: int = 0 +for y in range(len(lst)): + lst[y] += "." + for x in range(len(lst[y])): + if (lst[y][x].isdigit()): + end += 1; + elif (end != 0): + if (get_symbol_around(lst, (x - end, y), end)): + value += int(lst[y][x - end:x]) + else: + print(f"./input.txt:{y + 1}:{x}") + end = 0; + +print(value) \ No newline at end of file