2024-12-11 09:25:06 +01:00
|
|
|
from halo import Halo
|
|
|
|
from argparse import ArgumentParser
|
2024-12-11 07:22:39 +01:00
|
|
|
|
2024-12-11 09:25:06 +01:00
|
|
|
spinner = Halo(text="Blinking all the stones", spinner="dots")
|
|
|
|
def main(input, iterations):
|
|
|
|
spinner.start()
|
2024-12-11 07:22:39 +01:00
|
|
|
input_list: list = input.split(" ")
|
2024-12-11 09:25:06 +01:00
|
|
|
for _ in range(iterations):
|
2024-12-11 07:22:39 +01:00
|
|
|
new_stones = []
|
|
|
|
for num in input_list:
|
|
|
|
if num == '0':
|
|
|
|
new_stones.extend(["1"])
|
|
|
|
elif len(num) % 2 == 0:
|
|
|
|
half = len(num) // 2
|
|
|
|
left_half = str(int(num[:half]))
|
|
|
|
right_half = str(int(num[half:]))
|
|
|
|
|
|
|
|
new_stones.extend([left_half, right_half])
|
|
|
|
else:
|
|
|
|
new_stones.extend([str(int(num)*2024)])
|
|
|
|
input_list = new_stones
|
2024-12-11 09:25:06 +01:00
|
|
|
return len(input_list)
|
2024-12-11 07:22:39 +01:00
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
2024-12-11 09:25:06 +01:00
|
|
|
args = ArgumentParser(
|
|
|
|
prog="Advend of Code Day 11",
|
|
|
|
description="Solves the puzzle for day 11"
|
|
|
|
)
|
|
|
|
args.add_argument("-p", "--part")
|
|
|
|
args.add_argument("-f", "--file")
|
|
|
|
args = args.parse_args()
|
|
|
|
input_text = open(args.file, 'r').read()
|
|
|
|
iterations = 25 if args.part == "1" else 75 if args.part == "2" else None
|
|
|
|
answer = main(input_text, iterations)
|
|
|
|
spinner.succeed(str(answer))
|