Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def day9_part1(s):
- values = list(map(int, list(s.strip())))
- last_index = len(values) // 2
- checksum = position = index = i = 0
- while i < len(values):
- for _ in range(values[i]):
- checksum += position * index
- position += 1
- i += 1
- index += 1
- if i < len(values):
- for _ in range(values[i]):
- while i + 1 < len(values):
- if values[-1]:
- checksum += position * last_index
- position += 1
- values[-1] -= 1
- break
- values.pop(), values.pop()
- last_index -= 1
- i += 1
- return checksum
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement