From bef72df7941b406be9d1007dac2c352069e68035 Mon Sep 17 00:00:00 2001 From: augustin64 Date: Sat, 23 Dec 2023 15:28:25 +0100 Subject: [PATCH] Create aoc_utils --- aoc_utils/__init__.py | 0 aoc_utils/constants.py | 13 +++++++++++++ aoc_utils/decorators.py | 13 +++++++++++++ 3 files changed, 26 insertions(+) create mode 100644 aoc_utils/__init__.py create mode 100644 aoc_utils/constants.py create mode 100644 aoc_utils/decorators.py diff --git a/aoc_utils/__init__.py b/aoc_utils/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/aoc_utils/constants.py b/aoc_utils/constants.py new file mode 100644 index 0000000..77ec03b --- /dev/null +++ b/aoc_utils/constants.py @@ -0,0 +1,13 @@ +arrows_dir ={ + '^': (-1, 0), + 'v': (1, 0), + '<': (0, -1), + '>': (0, 1) +} + +cardinal_dir = [ + (1, 0), + (-1,0), + (0, 1), + (0, -1) +] \ No newline at end of file diff --git a/aoc_utils/decorators.py b/aoc_utils/decorators.py new file mode 100644 index 0000000..a6b5c71 --- /dev/null +++ b/aoc_utils/decorators.py @@ -0,0 +1,13 @@ +from functools import cache, wraps +import time + +def timeit(func): + @wraps(func) + def timeit_wrapper(*args, **kwargs): + start_time = time.perf_counter() + result = func(*args, **kwargs) + end_time = time.perf_counter() + total_time = end_time - start_time + print(f'===== {func.__name__}: {total_time:.4f}s =====') + return result + return timeit_wrapper \ No newline at end of file