Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from sys import argv
- def parse(src):
- '''Convert the input to a list of integers.'''
- return [int(x) for x in src.split()]
- def step(stones):
- '''Perform one blink.'''
- new_stones = list()
- for stone in stones:
- if stone == 0:
- new_stones.append(1)
- continue
- stone_str = str(stone)
- if len(stone_str) % 2 == 0:
- middle = len(stone_str) // 2
- new_stones += [int(stone_str[:middle]), int(stone_str[middle:])]
- else:
- new_stones.append(stone * 2024)
- return new_stones
- def main(stones):
- '''Perform 25 blinks and return the total number of stones.'''
- for _ in range(25):
- stones = step(stones)
- return len(stones)
- if __name__ == '__main__':
- # pass the path to the puzzle input as the first argument
- print(main(parse(open(argv[1]).read())))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement