11# Python Standard Library Imports
22import re
33
4- from utils import ingest
4+ from utils import (
5+ BaseSolution ,
6+ config ,
7+ main ,
8+ solution ,
9+ )
510
611
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+ }
916
10- # INPUT_FILE = '06.test.in'
11- # EXPECTED_ANSWERS = (1000000 - (1000000 - 1000 - 4), 3001997, )
1217
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
2422 self .instructions = [Instruction (instruction ) for instruction in data ]
2523 self .light_show = LightShow (self .instructions )
2624
@@ -36,7 +34,9 @@ def solve2(self):
3634
3735
3836class 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+ )
4040
4141 def __init__ (self , instruction ):
4242 self .instruction = instruction
@@ -57,15 +57,19 @@ def __init__(self, instructions):
5757 self .instructions = instructions
5858
5959 self .lights = [
60- [False , ] * 1000
61- for x
62- in range (1000 )
60+ [
61+ False ,
62+ ]
63+ * 1000
64+ for x in range (1000 )
6365 ]
6466
6567 self .lights2 = [
66- [0 , ] * 1000
67- for x
68- in range (1000 )
68+ [
69+ 0 ,
70+ ]
71+ * 1000
72+ for x in range (1000 )
6973 ]
7074
7175 def run (self ):
@@ -86,7 +90,7 @@ def run(self):
8690 elif operation == 'turn off' :
8791 lights [i ][j ] = False
8892 elif operation == 'toggle' :
89- lights [i ][j ] = not (lights [i ][j ])
93+ lights [i ][j ] = not (lights [i ][j ])
9094 else :
9195 raise Exception ('Illegal operation: %s' % operation )
9296
0 commit comments