Skip to content

Commit ca2517c

Browse files
committed
Base class for Solutions
Solution for day "nr" can calculate part solutions 1 and 2 Input is loaded from file "input.txt" inside the folder of the day Solutions of a day have to define their own calculate method
1 parent e5b4afd commit ca2517c

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

lib/solution.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
class Solution:
2+
def __init__(self, nr):
3+
self.nr = nr
4+
self.input = ""
5+
self.solution = ["(not calculated)", "(not calculated)"]
6+
self.calculated = [False, False]
7+
8+
def __str__(self):
9+
return "Solution 1: {}\nSolution 2: {}".format(self.solution[0], self.solution[1])
10+
11+
def calculate(self):
12+
raise NotImplementedError('users must define calculate to use this base class')
13+
14+
def get_solution(self, nr):
15+
if nr in [1, 2]:
16+
return self.solution[nr-1]
17+
18+
def set_solution(self, nr, value):
19+
if nr in [1, 2]:
20+
self.solution[nr-1] = value
21+
self.calculated[nr-1] = True
22+
23+
def is_calculated(self, nr):
24+
if nr in [1, 2]:
25+
return self.calculated[nr-1]
26+
27+
def read_input(self):
28+
with open(self.nr+"/input.txt", "r") as f:
29+
self.input = f.read()

0 commit comments

Comments
 (0)