1
1
# Python Standard Library Imports
2
2
import re
3
3
4
- from utils import ingest
4
+ from utils import (
5
+ BaseSolution ,
6
+ config ,
7
+ main ,
8
+ solution ,
9
+ )
5
10
6
11
7
- INPUT_FILE = '06.in'
8
- EXPECTED_ANSWERS = (543903 , 14687245 , )
12
+ config .EXPECTED_ANSWERS = (543903 , 14687245 )
13
+ config .TEST_CASES = {
14
+ '' : (1_000_000 - 1_000 - 4 , 3001997 ),
15
+ }
9
16
10
- # INPUT_FILE = '06.test.in'
11
- # EXPECTED_ANSWERS = (1000000 - (1000000 - 1000 - 4), 3001997, )
12
17
13
-
14
- def main ():
15
- solution = Solution ()
16
- answers = (solution .solve1 (), solution .solve2 (), )
17
- print (answers )
18
- assert (answers == EXPECTED_ANSWERS )
19
-
20
-
21
- class Solution :
22
- def __init__ (self ):
23
- data = ingest (INPUT_FILE )
18
+ @solution
19
+ class Solution (BaseSolution ):
20
+ def process_data (self ):
21
+ data = self .data
24
22
self .instructions = [Instruction (instruction ) for instruction in data ]
25
23
self .light_show = LightShow (self .instructions )
26
24
@@ -36,7 +34,9 @@ def solve2(self):
36
34
37
35
38
36
class Instruction :
39
- REGEXP = re .compile (r'^(?P<operation>(turn on)|(turn off)|(toggle)) (?P<x1>\d+),(?P<y1>\d+) through (?P<x2>\d+),(?P<y2>\d+)$' )
37
+ REGEXP = re .compile (
38
+ r'^(?P<operation>(turn on)|(turn off)|(toggle)) (?P<x1>\d+),(?P<y1>\d+) through (?P<x2>\d+),(?P<y2>\d+)$'
39
+ )
40
40
41
41
def __init__ (self , instruction ):
42
42
self .instruction = instruction
@@ -57,15 +57,19 @@ def __init__(self, instructions):
57
57
self .instructions = instructions
58
58
59
59
self .lights = [
60
- [False , ] * 1000
61
- for x
62
- in range (1000 )
60
+ [
61
+ False ,
62
+ ]
63
+ * 1000
64
+ for x in range (1000 )
63
65
]
64
66
65
67
self .lights2 = [
66
- [0 , ] * 1000
67
- for x
68
- in range (1000 )
68
+ [
69
+ 0 ,
70
+ ]
71
+ * 1000
72
+ for x in range (1000 )
69
73
]
70
74
71
75
def run (self ):
@@ -86,7 +90,7 @@ def run(self):
86
90
elif operation == 'turn off' :
87
91
lights [i ][j ] = False
88
92
elif operation == 'toggle' :
89
- lights [i ][j ] = not (lights [i ][j ])
93
+ lights [i ][j ] = not (lights [i ][j ])
90
94
else :
91
95
raise Exception ('Illegal operation: %s' % operation )
92
96
0 commit comments