This commit is contained in:
Bruno BELANYI 2025-12-01 08:54:08 +00:00
parent efa485c08c
commit f5cfe82b25
4 changed files with 8696 additions and 0 deletions

27
2025/d01/ex1/ex1.py Executable file
View 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()

4317
2025/d01/ex1/input Normal file

File diff suppressed because it is too large Load diff

35
2025/d01/ex2/ex2.py Executable file
View file

@ -0,0 +1,35 @@
#!/usr/bin/env python
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)
start = 50
zeros = 0
for delta in turns:
if delta < 0:
to_zero = (start % 100) or 100
else:
to_zero = 100 - (start % 100)
start += delta
if abs(delta) >= to_zero:
zeros += (abs(delta) - to_zero) // 100 + 1
return zeros
def main() -> None:
input = sys.stdin.read().splitlines()
print(solve(input))
if __name__ == "__main__":
main()

4317
2025/d01/ex2/input Normal file

File diff suppressed because it is too large Load diff