From b5d4852d82dd12a005c0d981127219f115549325 Mon Sep 17 00:00:00 2001 From: Stefan Harmuth Date: Tue, 1 Dec 2020 08:40:31 +0100 Subject: [PATCH] main.py running all days --- aoclib/__init__.py | 1 + aoclib/output.py | 2 ++ day1.py => day01.py | 10 +++++++--- day1_2.py => day01_2.py | 12 ++++++++++-- main.py | 10 ++++++++++ 5 files changed, 30 insertions(+), 5 deletions(-) create mode 100644 aoclib/output.py rename day1.py => day01.py (60%) rename day1_2.py => day01_2.py (61%) create mode 100644 main.py diff --git a/aoclib/__init__.py b/aoclib/__init__.py index 1dfaf1d..8698e18 100644 --- a/aoclib/__init__.py +++ b/aoclib/__init__.py @@ -1 +1,2 @@ from .inputs import * +from .output import * diff --git a/aoclib/output.py b/aoclib/output.py new file mode 100644 index 0000000..d7a9c78 --- /dev/null +++ b/aoclib/output.py @@ -0,0 +1,2 @@ +def printSolution(day, part, solution): + print(f"Solution to day {day}, part {part}: {solution}") diff --git a/day1.py b/day01.py similarity index 60% rename from day1.py rename to day01.py index 29ffa99..51b1346 100644 --- a/day1.py +++ b/day01.py @@ -1,13 +1,17 @@ import aoclib -import sys #my_input = [1721, 979, 366, 299, 675, 1456] # debug input my_input = aoclib.getInputLineAsArray(1, int) +globalBreak = False while len(my_input) > 0: try_value = my_input.pop() for value in my_input: if try_value + value == 2020: - print(try_value * value) - sys.exit(0) + aoclib.printSolution(1, 1, try_value * value) + globalBreak = True + break + + if globalBreak: + break diff --git a/day1_2.py b/day01_2.py similarity index 61% rename from day1_2.py rename to day01_2.py index 14a93bd..5a483f6 100644 --- a/day1_2.py +++ b/day01_2.py @@ -4,6 +4,7 @@ import sys #my_input = [1721, 979, 366, 299, 675, 1456] # debug input my_input = aoclib.getInputLineAsArray(1, int) +globalBreak = False while len(my_input) > 0: try_value = my_input.pop() for value_1 in my_input: @@ -11,6 +12,13 @@ while len(my_input) > 0: if value_1 == value_2: continue if try_value + value_1 + value_2 == 2020: - print(try_value * value_1 * value_2) - sys.exit(0) + aoclib.printSolution(1, 2, try_value * value_1 * value_2) + globalBreak = True + break + + if globalBreak: + break + + if globalBreak: + break diff --git a/main.py b/main.py new file mode 100644 index 0000000..0359e47 --- /dev/null +++ b/main.py @@ -0,0 +1,10 @@ +import aoclib +import os + +for _, _, files in os.walk(aoclib.BASE_PATH): + for f in files: + if f.startswith('day') and f.endswith('.py'): + exec(open(f).read()) + + break +