Skip to content

Commit f0510ee

Browse files
committed
cleanup AoC 2015.12 solutions #1-9
1 parent 6d20636 commit f0510ee

File tree

11 files changed

+180
-220
lines changed

11 files changed

+180
-220
lines changed

adventofcode/2015/01.py

+10-14
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,20 @@
11
from utils import (
2-
InputConfig,
3-
ingest,
2+
BaseSolution,
3+
config,
4+
main,
5+
solution,
46
)
57

68

7-
INPUT_FILE = '01.in'
8-
EXPECTED_ANSWERS = (74, 1795, )
9+
config.EXPECTED_ANSWERS = (74, 1795)
910

11+
config.INPUT_CONFIG.as_oneline = True
1012

11-
def main():
12-
solution = Solution()
13-
answers = (solution.solve1(), solution.solve2(), )
14-
print(answers)
15-
assert(answers == EXPECTED_ANSWERS)
1613

17-
18-
class Solution:
19-
def __init__(self):
20-
data = ingest(INPUT_FILE, InputConfig(as_oneline=True))
21-
self.instructions = data
14+
@solution
15+
class Solution(BaseSolution):
16+
def process_data(self):
17+
self.instructions = self.data
2218

2319
def solve1(self):
2420
floor = 0

adventofcode/2015/02.py

+19-20
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,17 @@
1-
from utils import ingest
1+
from utils import (
2+
BaseSolution,
3+
config,
4+
main,
5+
solution,
6+
)
27

38

4-
INPUT_FILE = '02.in'
5-
EXPECTED_ANSWERS = (1588178, 3783758, )
9+
config.EXPECTED_ANSWERS = (1588178, 3783758)
610

711

8-
def main():
9-
solution = Solution()
10-
answers = (solution.solve1(), solution.solve2(), )
11-
print(answers)
12-
assert(answers == EXPECTED_ANSWERS)
13-
14-
15-
class Solution:
16-
def __init__(self):
17-
self.data = ingest(INPUT_FILE)
12+
@solution
13+
class Solution(BaseSolution):
14+
def process_data(self):
1815
self.presents = [Present(dimensions) for dimensions in self.data]
1916

2017
def solve1(self):
@@ -33,7 +30,7 @@ def __init__(self, dimensions):
3330
@property
3431
def surface_area(self):
3532
l, w, h = self.l, self.w, self.h
36-
area = 2*l*w + 2*w*h + 2*h*l
33+
area = 2 * l * w + 2 * w * h + 2 * h * l
3734
return area
3835

3936
@property
@@ -50,11 +47,13 @@ def lh_area(self):
5047

5148
@property
5249
def smallest_side_area(self):
53-
return min([
54-
self.lw_area,
55-
self.wh_area,
56-
self.lh_area,
57-
])
50+
return min(
51+
[
52+
self.lw_area,
53+
self.wh_area,
54+
self.lh_area,
55+
]
56+
)
5857

5958
@property
6059
def wrapping_paper_area(self):
@@ -63,7 +62,7 @@ def wrapping_paper_area(self):
6362
@property
6463
def smallest_perimeter(self):
6564
a, b, c = sorted([self.l, self.w, self.h])
66-
return 2*a + 2*b
65+
return 2 * a + 2 * b
6766

6867
@property
6968
def volume(self):

adventofcode/2015/03.py

+10-14
Original file line numberDiff line numberDiff line change
@@ -2,26 +2,22 @@
22
from collections import defaultdict
33

44
from utils import (
5-
InputConfig,
6-
ingest,
5+
BaseSolution,
6+
config,
7+
main,
8+
solution,
79
)
810

911

10-
INPUT_FILE = '03.in'
11-
EXPECTED_ANSWERS = (2565, 2639, )
12+
config.EXPECTED_ANSWERS = (2565, 2639)
1213

14+
config.INPUT_CONFIG.as_oneline = True
1315

14-
def main():
15-
solution = Solution()
16-
answers = (solution.solve1(), solution.solve2(), )
17-
print(answers)
18-
assert(answers == EXPECTED_ANSWERS)
1916

20-
21-
class Solution:
22-
def __init__(self):
23-
data = ingest(INPUT_FILE, InputConfig(as_oneline=True))
24-
self.directions = data
17+
@solution
18+
class Solution(BaseSolution):
19+
def process_data(self):
20+
self.directions = self.data
2521
self.delivery_map = DeliveryMap(self.directions)
2622

2723
def solve1(self):

adventofcode/2015/04.py

+11-17
Original file line numberDiff line numberDiff line change
@@ -2,29 +2,23 @@
22
import hashlib
33

44
from utils import (
5-
InputConfig,
6-
ingest,
5+
BaseSolution,
6+
config,
7+
main,
8+
solution,
79
)
810

911

10-
INPUT_FILE = '04.in'
11-
EXPECTED_ANSWERS = (254575, 1038736, )
12+
config.EXPECTED_ANSWERS = (254575, 1038736)
13+
config.TEST_CASES = {'': (609043, 6742839)}
1214

13-
# INPUT_FILE = '4.test.in'
14-
# EXPECTED_ANSWERS = (609043, 6742839, )
15+
config.INPUT_CONFIG.as_oneline = True
1516

1617

17-
def main():
18-
solution = Solution()
19-
answers = (solution.solve1(), solution.solve2(), )
20-
print(answers)
21-
assert(answers == EXPECTED_ANSWERS)
22-
23-
24-
class Solution:
25-
def __init__(self):
26-
data = ingest(INPUT_FILE, InputConfig(as_oneline=True))
27-
self.key = data
18+
@solution
19+
class Solution(BaseSolution):
20+
def process_data(self):
21+
self.key = self.data
2822

2923
def solve1(self):
3024
n = 1

adventofcode/2015/05.py

+18-27
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,20 @@
1-
from utils import ingest
1+
from utils import (
2+
BaseSolution,
3+
config,
4+
main,
5+
solution,
6+
)
27

38

4-
INPUT_FILE = '05.in'
5-
EXPECTED_ANSWERS = (255, 55, )
9+
config.EXPECTED_ANSWERS = (255, 55)
10+
config.TEST_CASES = {
11+
'': (2, 2),
12+
}
613

7-
# INPUT_FILE = '05.test.in'
8-
# EXPECTED_ANSWERS = (2, 2, )
914

10-
11-
def main():
12-
solution = Solution()
13-
answers = (solution.solve1(), solution.solve2(), )
14-
print(answers)
15-
assert(answers == EXPECTED_ANSWERS)
16-
17-
18-
class Solution:
19-
def __init__(self):
20-
self.data = ingest(INPUT_FILE)
15+
@solution
16+
class Solution(BaseSolution):
17+
def process_data(self):
2118
self.strings = [NaughtyOrNice(s) for s in self.data]
2219

2320
def solve1(self):
@@ -53,10 +50,7 @@ def contains_naughty(self):
5350

5451
@property
5552
def contains_3_vowels(self):
56-
vowels = [
57-
c for c in self.s
58-
if c in self.VOWELS
59-
]
53+
vowels = [c for c in self.s if c in self.VOWELS]
6054
has_3 = len(vowels) >= 3
6155
return has_3
6256

@@ -88,9 +82,9 @@ def has_distinct_repeating_pair(self):
8882
has_repeat = False
8983

9084
for i in range(len(s) - 4 + 1):
91-
pair = s[i:i + 2]
92-
for j in range(i+2, len(s) - 2 + 1):
93-
pair2 = s[j:j + 2]
85+
pair = s[i : i + 2]
86+
for j in range(i + 2, len(s) - 2 + 1):
87+
pair2 = s[j : j + 2]
9488
if pair == pair2:
9589
has_repeat = True
9690
break
@@ -115,10 +109,7 @@ def has_3_palindrome(self):
115109

116110
@property
117111
def is_nice2(self):
118-
is_nice = (
119-
self.has_distinct_repeating_pair
120-
and self.has_3_palindrome
121-
)
112+
is_nice = self.has_distinct_repeating_pair and self.has_3_palindrome
122113

123114
return is_nice
124115

adventofcode/2015/06.py

+28-24
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,24 @@
11
# Python Standard Library Imports
22
import 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

3836
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+
)
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

adventofcode/2015/06.test.in

-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
11
turn on 0,0 through 999,999
22
toggle 0,0 through 999,0
33
turn off 499,499 through 500,500
4-
turn on 0,0 through 0,0
5-
toggle 0,0 through 999,999

0 commit comments

Comments
 (0)