summaryrefslogtreecommitdiffstats
path: root/utils.py
diff options
context:
space:
mode:
authorTomasz Kramkowski <tk@the-tk.com>2021-12-03 16:56:16 +0000
committerTomasz Kramkowski <tk@the-tk.com>2021-12-03 16:56:54 +0000
commitd75a9d510ced0a29ad2fe7ebc247dc7b0766320c (patch)
tree3bf55422bf79ce41ac62e20da7906321c2ec8992 /utils.py
parentb5d1f2d79bb61afd9b03621282b7bff5f29a75f1 (diff)
downloadaoc2021-d75a9d510ced0a29ad2fe7ebc247dc7b0766320c.tar.gz
aoc2021-d75a9d510ced0a29ad2fe7ebc247dc7b0766320c.tar.xz
aoc2021-d75a9d510ced0a29ad2fe7ebc247dc7b0766320c.zip
Implement open_day utility function
Diffstat (limited to 'utils.py')
-rw-r--r--utils.py6
1 files changed, 6 insertions, 0 deletions
diff --git a/utils.py b/utils.py
index d322ed0..91b90ff 100644
--- a/utils.py
+++ b/utils.py
@@ -1,6 +1,7 @@
from collections import deque
from collections.abc import Iterable, Iterator, Generator
from itertools import islice
+from sys import argv
from typing import TypeVar
T = TypeVar('T')
@@ -13,3 +14,8 @@ def sliding_window(iterable: Iterable[T], n: int) -> Generator[tuple[T, ...], No
for x in it:
window.append(x)
yield tuple(window)
+
+def open_day(n: int):
+ if len(argv) == 2:
+ return open(argv[1])
+ return open(f'{n}.in')