summaryrefslogtreecommitdiffstats
path: root/20
diff options
context:
space:
mode:
authorGustav Sörnäs <gustav@sornas.net>2020-12-09 08:50:09 +0100
committerGustav Sörnäs <gustav@sornas.net>2020-12-09 08:50:09 +0100
commit7115384f5634dcba134f5d1bb61f45e8f39a9ce2 (patch)
tree778afd8185f97df3c357f4fe0ea8436a78616988 /20
parent896eef2d5efc72eda8c772718ede1afc1cc8dd98 (diff)
downloadaoc-7115384f5634dcba134f5d1bb61f45e8f39a9ce2.tar.gz
add args to driver
Diffstat (limited to '20')
-rw-r--r--20/py/aoc20.py44
1 files changed, 43 insertions, 1 deletions
diff --git a/20/py/aoc20.py b/20/py/aoc20.py
index 3bd8994..9380915 100644
--- a/20/py/aoc20.py
+++ b/20/py/aoc20.py
@@ -24,16 +24,58 @@ if __name__ == "__main__":
import d08
import d09
+ skip = set()
+ only = set()
+ only_part = 0
+ run_times = 1
+
+ argv, argc = sys.argv, len(sys.argv)
+ i = 1
+ while i < argc:
+ if argv[i] == "--help":
+ print(f"usage: {argv[0]} [--help] [--time [times]] [--skip <n> <n> ...] [--only <n> <n> ...] [--part 0|1|2]")
+ sys.exit(0)
+ elif argv[i] == "--time":
+ i += 1
+ if i < argc and not argv[i].startswith("-"):
+ run_times = int(argv[i])
+ i += 1
+ else:
+ run_times = 10
+ elif argv[i] == "--skip":
+ i += 1
+ while i < argc and not argv[i].startswith("-"):
+ skip.add(int(argv[i]))
+ i += 1
+ elif argv[i] == "--only":
+ i += 1
+ while i < argc and not argv[i].startswith("-"):
+ only.add(int(argv[i]))
+ i += 1
+ elif argv[i] == "--part":
+ i += 1
+ only_part = int(argv[i])
+ i += 1
+ else:
+ print(f"unknown argument {argv[i]}")
+ print(f"maybe try {argv[0]} --help ?")
+ i += 1
+
+
print("day part | time | tot_time | ans")
print("---------+--------+----------+-----------")
time_to_here = 0
for day, mod in enumerate((d01, d02, d03, d04, d05,
d06, d07, d08, d09)):
+ if day+1 in skip or (only and day+1 not in only):
+ continue
input = open(f"../input/{day+1:02}").readlines()
for part, part_func in enumerate((mod.pt1, mod.pt2)):
+ if only_part != 0 and part+1 != only_part:
+ continue
times = []
- for i in range(100 if "time" in sys.argv else 5):
+ for i in range(run_times):
start = time.time()
ans = part_func(input)
ans_time = time.time()