Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def day9_part2(s):
- values = list(map(int, s.strip() + '0'))
- nums, skips = values[::2], values[1::2]
- positions = np.cumsum([0, 0] + values)[1::2]
- empty_index = [0] * 10 # First possible empty space of each size.
- checksum = 0
- for i1 in reversed(range(len(nums))):
- n = nums[i1]
- position = positions[i1]
- for i0 in range(empty_index[n], i1):
- if skips[i0] >= n:
- position = positions[i0 + 1] - skips[i0]
- skips[i0] -= n
- break
- empty_index[n] = i0
- for _ in range(n):
- checksum += position * i1
- position += 1
- return checksum
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement