Skip to content

Instantly share code, notes, and snippets.

@spellgen
Created December 2, 2025 23:56
Show Gist options
  • Select an option

  • Save spellgen/7b2b028c7058514d168c325a2468b04c to your computer and use it in GitHub Desktop.

Select an option

Save spellgen/7b2b028c7058514d168c325a2468b04c to your computer and use it in GitHub Desktop.
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