Created
December 2, 2025 23:56
-
-
Save spellgen/7b2b028c7058514d168c325a2468b04c to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def solve01b(fname: str): | |
| with open(fname, 'r') as f: | |
| pos = 50 | |
| zeroCount = 0 | |
| n = 0 | |
| for line in f: | |
| direction = line[0] | |
| distance = int(line[1:].strip()) | |
| if direction == 'L': | |
| mod = (pos - distance) % 100 | |
| needed = pos if pos > 0 else 100 | |
| elif direction == 'R': | |
| mod = (pos + distance) % 100 | |
| needed = 100 - pos | |
| if distance >= needed: | |
| zeroCount += (distance - needed) // 100 + 1 | |
| pos = mod | |
| n += 1 | |
| print(f"Final position: {pos}, n={n}") | |
| print(f"Zero count: {zeroCount}") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment