Compare commits
No commits in common. "0863c640f7cb22d801bd39f73fdbafc7f5bdc3fa" and "efa485c08c0e99d4f0d8052d6c5e58f9943d1627" have entirely different histories.
0863c640f7
...
efa485c08c
4 changed files with 0 additions and 8701 deletions
|
|
@ -1,27 +0,0 @@
|
|||
#!/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
4317
2025/d01/ex1/input
File diff suppressed because it is too large
Load diff
|
|
@ -1,40 +0,0 @@
|
|||
#!/usr/bin/env python
|
||||
|
||||
import itertools
|
||||
import sys
|
||||
|
||||
|
||||
def sign(n: int) -> int:
|
||||
if n == 0:
|
||||
return 0
|
||||
return n // abs(n)
|
||||
|
||||
|
||||
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]
|
||||
|
||||
def count_zeros(before: int, after: int) -> int:
|
||||
delta = after - before
|
||||
to_zero = (before % 100) * -sign(delta)
|
||||
if to_zero <= 0:
|
||||
to_zero += 100
|
||||
return (abs(delta) + 100 - to_zero) // 100
|
||||
|
||||
turns = parse(input)
|
||||
positions = itertools.accumulate(turns, initial=50)
|
||||
return sum(count_zeros(a, b) for a, b in itertools.pairwise(positions))
|
||||
|
||||
|
||||
def main() -> None:
|
||||
input = sys.stdin.read().splitlines()
|
||||
print(solve(input))
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
4317
2025/d01/ex2/input
4317
2025/d01/ex2/input
File diff suppressed because it is too large
Load diff
Loading…
Add table
Add a link
Reference in a new issue