2025: d01: ex1: add solution
This commit is contained in:
parent
e1a2c362ec
commit
95f307a0d6
1 changed files with 27 additions and 0 deletions
27
2025/d01/ex1/ex1.py
Executable file
27
2025/d01/ex1/ex1.py
Executable file
|
|
@ -0,0 +1,27 @@
|
||||||
|
#!/usr/bin/env python
|
||||||
|
|
||||||
|
import itertools
|
||||||
|
import sys
|
||||||
|
|
||||||
|
|
||||||
|
def solve(input: list[str]) -> int:
|
||||||
|
def parse_turn(input: str) -> int:
|
||||||
|
direction = input[0]
|
||||||
|
clicks = int(input[1:])
|
||||||
|
return clicks * (1 if direction == "R" else -1)
|
||||||
|
|
||||||
|
def parse(input: list[str]) -> list[int]:
|
||||||
|
return [parse_turn(turn) for turn in input]
|
||||||
|
|
||||||
|
turns = parse(input)
|
||||||
|
positions = itertools.accumulate(turns, initial=50)
|
||||||
|
return sum(pos % 100 == 0 for pos in positions)
|
||||||
|
|
||||||
|
|
||||||
|
def main() -> None:
|
||||||
|
input = sys.stdin.read().splitlines()
|
||||||
|
print(solve(input))
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
main()
|
||||||
Loading…
Add table
Add a link
Reference in a new issue