add: 2024/day02/part1
This commit is contained in:
parent
b638d89a0a
commit
200a9c18a9
21
2024/day02/part1.py
Normal file
21
2024/day02/part1.py
Normal file
@ -0,0 +1,21 @@
|
||||
text: str
|
||||
|
||||
with open("input.txt") as f:
|
||||
text = f.read()
|
||||
|
||||
lines: list[str] = text.splitlines()
|
||||
|
||||
total: int = 0
|
||||
|
||||
for line in lines:
|
||||
numbers: list[int] = list(map(int, line.split(" ")))
|
||||
direction: int = (numbers[1] - numbers[0])
|
||||
if (direction == 0):
|
||||
continue
|
||||
direction = direction / abs(direction)
|
||||
for x1, x2 in zip(numbers[:-1], numbers[1:]):
|
||||
if ((x2 - x1) * direction not in range(1, 4)):
|
||||
break
|
||||
else:
|
||||
total += 1
|
||||
print(total)
|
Loading…
Reference in New Issue
Block a user