From 5e599b0f3a1397b45c3899b1d3ff75f4904fed1a Mon Sep 17 00:00:00 2001 From: Thibaud Date: Sat, 4 Jan 2025 15:03:39 +0100 Subject: [PATCH] 2024 add run script --- 2024/run.py | 42 ++++++++++++++++++++++++++++++++++++++++++ 2024/stats.txt | 17 +++++++++++++++++ 2 files changed, 59 insertions(+) create mode 100644 2024/run.py create mode 100644 2024/stats.txt diff --git a/2024/run.py b/2024/run.py new file mode 100644 index 0000000..401247f --- /dev/null +++ b/2024/run.py @@ -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) + diff --git a/2024/stats.txt b/2024/stats.txt new file mode 100644 index 0000000..c12b692 --- /dev/null +++ b/2024/stats.txt @@ -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 +