add: 2024/day06/part1

This commit is contained in:
Starnakin 2024-12-06 10:57:24 +01:00
parent 3c535c8036
commit 2d7ab5e287

42
2024/day06/part1.py Normal file
View File

@ -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)