diff options
Diffstat (limited to '2024')
-rw-r--r-- | 2024/day11/input | 1 | ||||
-rw-r--r-- | 2024/day11/input_test | 1 | ||||
-rw-r--r-- | 2024/day11/solve1_2.py | 50 |
3 files changed, 52 insertions, 0 deletions
diff --git a/2024/day11/input b/2024/day11/input new file mode 100644 index 0000000..6142429 --- /dev/null +++ b/2024/day11/input @@ -0,0 +1 @@ +4 4841539 66 5279 49207 134 609568 0
\ No newline at end of file diff --git a/2024/day11/input_test b/2024/day11/input_test new file mode 100644 index 0000000..528f9d5 --- /dev/null +++ b/2024/day11/input_test @@ -0,0 +1 @@ +125 17
\ No newline at end of file diff --git a/2024/day11/solve1_2.py b/2024/day11/solve1_2.py new file mode 100644 index 0000000..e2eef43 --- /dev/null +++ b/2024/day11/solve1_2.py @@ -0,0 +1,50 @@ +memoize = {} +class Globals: + memoize_used = 0 + +def count_digits(number: int) -> int: + if number == 0: + return 1 + + count = 0 + while number != 0: + number = number // 10 + count += 1 + + return count + +def count_after_blinks(stone: int, blink_remaining: int): + if blink_remaining == 0: + return 1 + + elif (stone, blink_remaining) in memoize: + Globals.memoize_used += 1 + return memoize[(stone, blink_remaining)] + + else: + if stone == 0: + result = count_after_blinks(1, blink_remaining - 1) + + else: + digits = count_digits(stone) + if digits % 2 == 0: + divisor = 10 ** (digits // 2) + result = count_after_blinks(stone % divisor, blink_remaining - 1) + count_after_blinks(stone // divisor, blink_remaining - 1) + + else: + result = count_after_blinks(stone * 2024, blink_remaining - 1) + + memoize[(stone, blink_remaining)] = result + return result + +data = [] +with open("input") as f: + data.extend((int(elem) for elem in f.read().strip().split())) + +count = 0 +for elem in data: + count += count_after_blinks(elem, 75) + print(f"elem {elem} done") + +print(Globals.memoize_used) +print(count)
\ No newline at end of file |