Skip to content

Commit 8771f13

Browse files
committed
Advent of Code: lint 2015
1 parent 90ddc1a commit 8771f13

14 files changed

Lines changed: 41 additions & 142 deletions

File tree

advent_of_code/2015/d01.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,13 @@
1111
class Day01(aoc.Challenge):
1212
"""Day 1: Not Quite Lisp. Count Santa's floor level."""
1313

14-
TESTS = (
14+
TESTS = [
1515
aoc.TestCase(inputs=SAMPLE[0], part=1, want=0),
1616
aoc.TestCase(inputs=SAMPLE[1], part=1, want=0),
1717
aoc.TestCase(inputs=SAMPLE[2], part=1, want=3),
1818
aoc.TestCase(inputs=SAMPLE[3], part=2, want=1),
1919
aoc.TestCase(inputs=SAMPLE[4], part=2, want=5),
20-
)
20+
]
2121

2222
def part1(self, puzzle_input: InputType) -> int:
2323
"""Return Santa's final floor."""

advent_of_code/2015/d02.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,12 @@
1313
class Day02(aoc.Challenge):
1414
"""Day 2: I Was Told There Would Be No Math. Compute wrapping materials."""
1515

16-
TESTS = (
16+
TESTS = [
1717
aoc.TestCase(inputs=SAMPLE[0], part=1, want=58),
1818
aoc.TestCase(inputs=SAMPLE[1], part=1, want=43),
1919
aoc.TestCase(inputs=SAMPLE[0], part=2, want=34),
2020
aoc.TestCase(inputs=SAMPLE[1], part=2, want=14),
21-
)
21+
]
2222
INPUT_PARSER = aoc.parse_ints
2323

2424
def part1(self, puzzle_input: InputType) -> int:

advent_of_code/2015/d03.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
#!/bin/python
22
"""Advent of Code: Day 03."""
33

4-
from collections.abc import Callable
5-
64
from lib import aoc
75

86
SAMPLE = ["^>v<", "^v^v^v^v^v"]
@@ -20,12 +18,12 @@ class Day03(aoc.Challenge):
2018
aoc.TestCase(inputs=SAMPLE[1], part=2, want=11),
2119
]
2220

23-
def solver(self, line: str, part_one: bool) -> int:
21+
def solver(self, puzzle_input: str, part_one: bool) -> int:
2422
"""Return how many houses get presents."""
2523
pos = {True: complex(0), False: complex(0)}
2624
robot = False
2725
visited = {pos[robot]}
28-
for char in line:
26+
for char in puzzle_input:
2927
pos[robot] += MAPPING[char]
3028
visited.add(pos[robot])
3129
if not part_one:

advent_of_code/2015/d04.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,11 @@ class Day04(aoc.Challenge):
1616
aoc.TestCase(inputs=SAMPLE[1], part=1, want=1048970),
1717
]
1818

19-
def solver(self, key: list[int], part_one: bool) -> int:
19+
def solver(self, puzzle_input: str, part_one: bool) -> int:
2020
"""Return a suffix which generates a hash starting with a given prefix."""
2121
size = 5 if part_one else 6
2222
prefix = "0" * size
23-
md5 = hashlib.md5(key.encode())
23+
md5 = hashlib.md5(puzzle_input.encode())
2424
for i in range(0, 100000000):
2525
md5copy = md5.copy()
2626
md5copy.update(str(i).encode())

advent_of_code/2015/d05.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
class Day05(aoc.Challenge):
2323
"""Day 5: Doesn't He Have Intern-Elves For This?. Classify strings as naughty or nice."""
2424

25-
TESTS = (
25+
TESTS = [
2626
aoc.TestCase(inputs=SAMPLE[0], part=1, want=1),
2727
aoc.TestCase(inputs=SAMPLE[1], part=1, want=1),
2828
aoc.TestCase(inputs=SAMPLE[2], part=1, want=0),
@@ -32,7 +32,7 @@ class Day05(aoc.Challenge):
3232
aoc.TestCase(inputs=SAMPLE[6], part=2, want=1),
3333
aoc.TestCase(inputs=SAMPLE[7], part=2, want=0),
3434
aoc.TestCase(inputs=SAMPLE[8], part=2, want=0),
35-
)
35+
]
3636

3737
def part1(self, puzzle_input: InputType) -> int:
3838
"""Return how many lines follow rules 1."""

advent_of_code/2015/d09.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,9 @@ def input_parser(self, puzzle_input: str) -> InputType:
3737
distances = {}
3838
locations: set[str] = set()
3939
for line in puzzle_input.splitlines():
40-
src, dst, dist_raw = LINE_RE.match(line).groups()
40+
m = LINE_RE.match(line)
41+
assert m
42+
src, dst, dist_raw = m.groups()
4143
dist = int(dist_raw)
4244

4345
distances[src, dst] = dist

advent_of_code/2015/d10.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ def look_say(string: str) -> str:
2424
else:
2525
return look_say(string[:split]) + look_say(string[split:])
2626

27-
out = []
27+
out: list[str] = []
2828
count = 0
2929
prior = string[0]
3030
for char in string:
@@ -48,7 +48,7 @@ class Day10(aoc.Challenge):
4848
INPUT_PARSER = aoc.parse_one_str
4949
TIMEOUT = 70
5050

51-
def look_say_loop(self, string: str, steps: int) -> str:
51+
def look_say_loop(self, string: str, steps: int) -> int:
5252
"""Return look-say length after looping."""
5353
for _ in range(5 if self.testing else steps):
5454
string = look_say(string)

advent_of_code/2015/d11.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ class Day11(aoc.Challenge):
5151

5252
TESTS = [
5353
aoc.TestCase(inputs=SAMPLE[0], part=1, want="abcdffaa"),
54-
#aoc.TestCase(inputs=SAMPLE[1], part=1, want="ghjaabcc"),
54+
# aoc.TestCase(inputs=SAMPLE[1], part=1, want="ghjaabcc"),
5555
aoc.TestCase(inputs=SAMPLE[0], part=2, want="abcdffbb"),
5656
]
5757

@@ -72,14 +72,14 @@ def next_password(self, password: str) -> str:
7272
password = "".join(string.ascii_lowercase[i] for i in parts(num))
7373
return password
7474

75-
def part1(self, puzzle_input: InputType) -> int:
75+
def part1(self, puzzle_input: InputType) -> str:
7676
"""Rotate once."""
7777
assert valid(parts(334140716)) # abcdffaa
7878
assert valid(parts(50460204602)) # ghjaabcc
7979

8080
return self.next_password(puzzle_input)
8181

82-
def part2(self, puzzle_input: InputType) -> int:
82+
def part2(self, puzzle_input: InputType) -> str:
8383
"""Rotate twice."""
8484
password = self.next_password(puzzle_input)
8585
return self.next_password(password)

advent_of_code/2015/d14.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
#!/bin/python
22
"""Advent of Code, Day 14: Reindeer Olympics."""
33

4-
import re
5-
64
from lib import aoc
75

86
SAMPLE = """\

advent_of_code/2015/d15.py

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@
99
Butterscotch: capacity -1, durability -2, flavor 6, texture 3, calories 8
1010
Cinnamon: capacity 2, durability 3, flavor -2, texture -1, calories 3"""
1111

12-
LineType = int
13-
InputType = list[LineType]
1412
PROPERTIES = "capacity durability flavor texture".split()
1513

1614

@@ -36,7 +34,7 @@ class Day15(aoc.Challenge):
3634
aoc.TestCase(inputs=SAMPLE, part=2, want=57600000),
3735
]
3836

39-
def sorted_limits(self, ingredients: InputType, check_calories: bool) -> int:
37+
def sorted_limits(self, ingredients: dict[str, dict[str, int]], check_calories: bool) -> list[tuple[int, str]]:
4038
"""Generate the acceptable ranges for each ingredient.
4139
4240
The upper limit of ingredients can be computed based on their
@@ -69,13 +67,13 @@ def sorted_limits(self, ingredients: InputType, check_calories: bool) -> int:
6967
limits[name] = min(limit, limits[name])
7068
return sorted((limit, name) for name, limit in limits.items())
7169

72-
def combo_generator_b(self, ingredients: InputType, check_calories: bool):
70+
def combo_generator_b(self, ingredients: dict[str, dict[str, int]], check_calories: bool):
7371
"""Generate amount combinations to try."""
7472
ranges, _ = list(zip(*self.sorted_limits(ingredients, check_calories)))
7573
for amounts in itertools.product(*[range(i + 1) for i in ranges[:-1]]):
7674
yield amounts + (100 - sum(amounts),)
7775

78-
def combo_generator(self, ingredients: InputType, check_calories: bool):
76+
def combo_generator(self, ingredients: dict[str, dict[str, int]], check_calories: bool):
7977
"""Generate amount combinations to try."""
8078
ranges, _ = list(zip(*self.sorted_limits(ingredients, check_calories)))
8179
num = len(ranges)
@@ -91,7 +89,7 @@ def combo_generator(self, ingredients: InputType, check_calories: bool):
9189
if sum(amounts) <= 100:
9290
break
9391

94-
def solver(self, puzzle_input: InputType, part_one: bool) -> int:
92+
def solver(self, puzzle_input: dict[str, dict[str, int]], part_one: bool) -> int:
9593
"""Solve for the optimal recipe."""
9694
check_calories = not part_one
9795
most = 0
@@ -111,11 +109,10 @@ def solver(self, puzzle_input: InputType, part_one: bool) -> int:
111109
))
112110
if total == 0:
113111
continue
114-
if total > most:
115-
most = total
112+
most = max(total, most)
116113
return most
117114

118-
def input_parser(self, puzzle_input: str) -> InputType:
115+
def input_parser(self, puzzle_input: str) -> dict[str, dict[str, int]]:
119116
"""Parse the input data."""
120117
data = {}
121118
for line in puzzle_input.splitlines():

0 commit comments

Comments
 (0)