Initial commit
This commit is contained in:
69
solve.py
Normal file
69
solve.py
Normal file
@@ -0,0 +1,69 @@
|
||||
import sys
|
||||
from time import time
|
||||
from importlib import import_module
|
||||
|
||||
from advent.errors import InvalidSessionIDError, PuzzleNotFoundError
|
||||
from advent.functions import get_puzzle_input
|
||||
|
||||
|
||||
def usage():
|
||||
print("Usage: python solve.py <day>")
|
||||
|
||||
|
||||
def main():
|
||||
if len(sys.argv) != 2:
|
||||
usage()
|
||||
sys.exit(1)
|
||||
|
||||
try:
|
||||
day = int(sys.argv[1])
|
||||
except ValueError:
|
||||
print("Day must be an integer")
|
||||
usage()
|
||||
sys.exit(1)
|
||||
|
||||
try:
|
||||
print(f"Loading 2024, day {day} solver")
|
||||
mod = import_module(f"puzzles.{day}")
|
||||
except ModuleNotFoundError:
|
||||
print(f"Solver for day {day} not found")
|
||||
sys.exit(1)
|
||||
|
||||
try:
|
||||
print("Fetching puzzle input...")
|
||||
puzzle_input = get_puzzle_input(2024, int(day))
|
||||
except (PuzzleNotFoundError, InvalidSessionIDError) as exc:
|
||||
print(exc)
|
||||
sys.exit(1)
|
||||
|
||||
try:
|
||||
print("Testing part 1 solution...")
|
||||
start = time()
|
||||
assert mod.solve_p1(mod.test_input) == mod.test_solution_p1
|
||||
print(f"Test passed in {time() - start:.3f} seconds")
|
||||
|
||||
print("Solving part 1...")
|
||||
start = time()
|
||||
solution_p1 = mod.solve_p1(puzzle_input)
|
||||
print(f"Part 1 solution: {solution_p1} ({time() - start:.3f} seconds)")
|
||||
|
||||
print("Testing part 2 solution...")
|
||||
start = time()
|
||||
assert mod.solve_p2(mod.test_input) == mod.test_solution_p2
|
||||
print(f"Test passed in {time() - start:.3f} seconds")
|
||||
|
||||
print("Solving part 2...")
|
||||
solution_p2 = mod.solve_p2(puzzle_input)
|
||||
print(f"Part 2 solution: {solution_p2} ({time() - start:.3f} seconds)")
|
||||
|
||||
except NotImplementedError:
|
||||
print("Puzzle solver is incomplete. Exiting")
|
||||
sys.exit(1)
|
||||
|
||||
except exc:
|
||||
print("Error:", exc)
|
||||
sys.exit(1)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
Reference in New Issue
Block a user