diff --git a/2024/day06/part1.py b/2024/day06/part1.py new file mode 100644 index 0000000..6769a27 --- /dev/null +++ b/2024/day06/part1.py @@ -0,0 +1,42 @@ +import math + +text: str + +with open("input.txt") as f: + text = f.read() + +total: int = 0 + +lines = text.split("\n") +lines = [list(line) for line in lines] + +x_max: int = len(lines[0]) +y_max: int = len(lines) + +spawn_index: int = text.index('^') + +x: int = spawn_index % (x_max + 1) +y: int = spawn_index // (x_max + 1) + +angle: int = math.pi * 3 / 2 + +while True: + new_x: int = round(x + math.cos(angle)) + new_y: int = round(y + math.sin(angle)) + + if (not (x_max > new_x >= 0 and y_max > new_y >= 0)): + break + + if (lines[new_y][new_x] == "#"): + angle += math.pi / 2 + continue + + x = new_x + y = new_y + if (lines[y][x] == '.'): + lines[y][x] = "X" + total += 1 + +print("\n".join(["".join(line) for line in lines])) + +print(total + 1) \ No newline at end of file