2024 add run script

This commit is contained in:
Thibaud Gasser 2025-01-04 15:03:39 +01:00
parent abb9d5ba1f
commit 5e599b0f3a
2 changed files with 59 additions and 0 deletions

42
2024/run.py Normal file
View File

@ -0,0 +1,42 @@
import sys
import time
import subprocess
from pathlib import Path
def main(day):
if day is not None:
path = Path(f"day{day}")
script_path = path / Path(f"day{day}.py")
input_path = path / Path("input.txt")
if not script_path.exists():
print(f"Invalid day {day}", file=sys.stderr)
exit(1)
if not input_path.exists():
print(f"Could not find input file {input_path}", file=sys.stderr)
exit(1)
run_day(script_path, input_path)
else:
for day in range(1, 26):
path = Path(f"day{day}")
script_path = path / Path(f"day{day}.py")
input_path = path / Path("input.txt")
if script_path.exists():
if not input_path.exists():
print(f"Could not find input file {input_path}, skipped day {day}.", file=sys.stderr)
continue
run_day(script_path, input_path)
def run_day(script_path, input_path):
start = time.time()
res = subprocess.run([sys.executable, script_path, input_path], check=True, stdout=subprocess.PIPE)
elapsed = time.time() - start
#print(res.stdout)
print(f"ran {script_path} in {elapsed:.3f}s")
if __name__ == "__main__":
day = sys.argv[1] if len(sys.argv) > 1 else None
main(day)

17
2024/stats.txt Normal file
View File

@ -0,0 +1,17 @@
ran day1/day1.py in 0.016s
ran day2/day2.py in 0.021s
ran day3/day3.py in 0.017s
ran day4/day4.py in 0.039s
ran day5/day5.py in 0.191s
ran day6/day6.py in 9.655s
ran day7/day7.py in 2.227s
ran day8/day8.py in 0.017s
ran day9/day9.py in 11.159s
ran day10/day10.py in 0.052s
ran day11/day11.py in 0.116s
ran day12/day12.py in 0.170s
ran day13/day13.py in 0.014s
ran day14/day14.py in 3.729s
ran day16/day16.py in 10.082s
ran day18/day18.py in 0.872s