From 234a7cacd33caddf97bde8f8c0536025dc0e8e50 Mon Sep 17 00:00:00 2001 From: Andreas Date: Wed, 11 Dec 2024 09:25:06 +0100 Subject: [PATCH] Made code sleeker :) --- day11/solution.py | 25 ++++++++++++++++++------- day11/solution2.py | 25 ------------------------- 2 files changed, 18 insertions(+), 32 deletions(-) delete mode 100644 day11/solution2.py diff --git a/day11/solution.py b/day11/solution.py index dee14bd..422ce63 100644 --- a/day11/solution.py +++ b/day11/solution.py @@ -1,9 +1,11 @@ -import sys -from tqdm import tqdm +from halo import Halo +from argparse import ArgumentParser -def main(input): +spinner = Halo(text="Blinking all the stones", spinner="dots") +def main(input, iterations): + spinner.start() input_list: list = input.split(" ") - for i in tqdm(range(25)): + for _ in range(iterations): new_stones = [] for num in input_list: if num == '0': @@ -17,9 +19,18 @@ def main(input): else: new_stones.extend([str(int(num)*2024)]) input_list = new_stones - print(len(input_list)) + return len(input_list) if __name__ == "__main__": - input_text = sys.stdin.read().strip() - main(input_text) + 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)) \ No newline at end of file diff --git a/day11/solution2.py b/day11/solution2.py deleted file mode 100644 index fc56087..0000000 --- a/day11/solution2.py +++ /dev/null @@ -1,25 +0,0 @@ -import sys -from tqdm import tqdm - -def main(input): - input_list: list = input.split(" ") - for i in tqdm(range(75)): - 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 - print(len(input_list)) - - -if __name__ == "__main__": - input_text = sys.stdin.read().strip() - main(input_text)