Skip to content

Commit

Permalink
[2024/11] remove the split() cache too?? it's also faster without
Browse files Browse the repository at this point in the history
  • Loading branch information
StarlitGhost committed Dec 11, 2024
1 parent 6b51fe6 commit 67d82aa
Showing 1 changed file with 0 additions and 20 deletions.
20 changes: 0 additions & 20 deletions 2024/11/script.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,16 @@
from GhostyUtils import aoc
import math
from functools import cache
from collections import Counter, defaultdict


aoc.argparser.add_argument("-n", "--num_blinks", default=0, type=int,
help="number of times to blink")
aoc.argparser.add_argument("-c", "--cache_info", action="store_true",
help="output cache info")


def num_digits(value: int) -> int:
return int(math.log10(value)) + 1


@cache
def split(value: int) -> tuple[int, int]:
tens_place = 10 ** (num_digits(value) // 2)
l_value = value // tens_place
Expand Down Expand Up @@ -47,13 +43,6 @@ def blink_n_times(stones: dict[int, int], n: int) -> dict[int, int]:
return stones


def print_cache_info():
split_cache = split.cache_info()
print(f"split: {split_cache.hits} hits, {split_cache.misses} misses"
f" | {split_cache.hits / (split_cache.hits + split_cache.misses) * 100:.1f}% hit rate")
split.cache_clear()


def main():
start_stones = Counter([int(stone) for stone in aoc.read().split()])
if aoc.args.verbose:
Expand All @@ -63,23 +52,14 @@ def main():
stones = blink_n_times(start_stones, aoc.args.num_blinks)
print(f"{aoc.args.num_blinks} blinks: {sum(stones.values())}")

if aoc.args.cache_info:
print_cache_info()

exit(0)

stones = blink_n_times(start_stones, 25)
print(f"p1: {sum(stones.values())}")

if aoc.args.cache_info:
print_cache_info()

stones = blink_n_times(start_stones, 75)
print(f"p2: {sum(stones.values())}")

if aoc.args.cache_info:
print_cache_info()


if __name__ == "__main__":
main()

0 comments on commit 67d82aa

Please sign in to comment.