Skip to content

Commit dbc8d53

Browse files
committed
Everybody Codes: lint 2025
1 parent 2d8334c commit dbc8d53

9 files changed

Lines changed: 40 additions & 65 deletions

File tree

everybody_codes/event2025/quest_01.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
"""Everyone Codes Day N."""
22

3-
import logging
4-
53
from lib import helpers
64
from lib import parsers
75

everybody_codes/event2025/quest_03.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
"""Everyone Codes Day N."""
22

33
import collections
4-
import time
54
from lib import helpers
65
from lib import parsers
76

everybody_codes/event2025/quest_06.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
import collections
44
import math
5-
import time
65
from lib import helpers
76

87

everybody_codes/event2025/quest_07.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
import collections
44
import functools
5-
import time
65
import typing
76
from lib import helpers
87
from lib import parsers

everybody_codes/event2025/quest_08.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
import collections
44
import logging
5-
import time
65
from lib import helpers
76
from lib import parsers
87

@@ -32,7 +31,7 @@ def solve(part: int, data: list[list[int]], testing: bool) -> int:
3231
)
3332

3433
# Count the occurance of lines between nails, in both directions.
35-
frequency = collections.defaultdict(lambda: collections.defaultdict(int))
34+
frequency: dict[int, dict[int, int]] = collections.defaultdict(lambda: collections.defaultdict(int))
3635
for a, b in lines:
3736
frequency[a][b] += 1
3837
frequency[b][a] += 1
@@ -41,7 +40,7 @@ def solve(part: int, data: list[list[int]], testing: bool) -> int:
4140
# We can count the lines that i-j cuts anchored by nail a
4241
# by looking at the difference between difference between lines from a-(j-1) and a-(i).
4342
# This gives the total lines from a to `[(i+1)..(j-1)]`.
44-
cumulative = collections.defaultdict(lambda: collections.defaultdict(int))
43+
cumulative: dict[int, dict[int, int]] = collections.defaultdict(lambda: collections.defaultdict(int))
4544
for a in range(1, size):
4645
for b in range(a + 1, a + size):
4746
cumulative[a][b % size] = cumulative[a][(b - 1) % size] + frequency[a][b % size]

everybody_codes/event2025/quest_09.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
import logging
44
import math
5-
import time
65
from lib import helpers
76
from lib import parsers
87

everybody_codes/event2025/quest_10.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
import collections.abc
44
import functools
5-
import time
65
from lib import helpers
76
from lib import parsers
87

@@ -53,7 +52,6 @@ def solve(part: int, data: helpers.Map, testing) -> int:
5352
dragons, initial_sheep, hideouts = (data.coords.get(i, set()) for i in "DS#")
5453
board = data.all_coords
5554
start = dragons.pop()
56-
bottom = data.max_y
5755
# If the sheep reaches this location, the game ends.
5856
game_over = {(x, data.max_y + 1) for x in range(data.width)}
5957
for _ in range(data.max_y):

everybody_codes/event2025/quest_11.py

Lines changed: 38 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
"""Everyone Codes Day N."""
22

33
import math
4-
import time
54
from lib import helpers
65
from lib import parsers
76

@@ -22,18 +21,25 @@ def experiment2(ducks):
2221
In this example, two ducks from col 1 can flow into the basin on cols 3-4.
2322
2423
1. Find a peak: any column taller than the next column.
25-
2. Find the basin: the first column shorter than the next one. Flow into here. Extend this basin if there are repeated low columns.
24+
2. Find the basin: the first column shorter than the next one. Flow into here.
25+
Extend this basin if there are repeated low columns.
2626
3. Determine how high the basin can be filled.
27-
3a. If the peak is adjacent to the basin: `(source - dest) / (width + 1) * width` (rounded up/down/maybe).
28-
3b. If the peak is not adjacent to the basin: `min( [source - source_neighbor], [basin_right - basin], [basin_left, basin] )`.
29-
4. Flood fill the basin, tracking movements. Source through basin edge have movement of flow amount. Basin tiles get moves equal to `sum(fill for that column and all basin columns to its right)`.
30-
5. Basin fill is a tad messy unless `flow_amount % basin_width == 0`. I used `basin_fills, extra = divmod(flow_amount, basin_width)` where the right `extra` spots of the basin get `basin_fills + 1` and the left part of the basin gets `basin_fills`.
27+
3a. If the peak is adjacent to the basin:
28+
`(source - dest) / (width + 1) * width` (rounded up/down/maybe).
29+
3b. If the peak is not adjacent to the basin:
30+
`min( [source - source_neighbor], [basin_right - basin], [basin_left, basin] )`.
31+
4. Flood fill the basin, tracking movements.
32+
Source through basin edge have movement of flow amount.
33+
Basin tiles get moves equal to `sum(fill for that column and all basin columns to its right)`.
34+
5. Basin fill is a tad messy unless `flow_amount % basin_width == 0`.
35+
I used `basin_fills, extra = divmod(flow_amount, basin_width)`
36+
where the right `extra` spots of the basin get `basin_fills + 1`
37+
and the left part of the basin gets `basin_fills`.
3138
"""
3239
big = sum(ducks)
3340
num = len(ducks) - 1
3441
moves = [0] * len(ducks)
3542

36-
steps = 0
3743
while any(a > b for a, b in zip(ducks, ducks[1:])):
3844
peak_idx, peak_height, peak_adjacent = next(
3945
(idx, a, b)
@@ -58,11 +64,24 @@ def experiment2(ducks):
5864

5965
# Maximum number of ducks that can move:
6066
# Don't overflow the basin and don't make the peak lower than its neighbor.
61-
fill_amount = min(peak_height - peak_adjacent, min(right_edge_height - basin_height, left_edge_height - basin_height) * basin_width)
67+
fill_amount = min(
68+
peak_height - peak_adjacent,
69+
min(
70+
right_edge_height - basin_height,
71+
left_edge_height - basin_height,
72+
) * basin_width,
73+
)
6274

6375
# If the peak is also the basin edge, don't make the peak lower than the basin height.
6476
if peak_idx + 1 == basin_start_idx:
65-
fill_amount = min(fill_amount, int(math.ceil((peak_height - peak_adjacent) * basin_width / (basin_width + 1))))
77+
fill_amount = min(
78+
fill_amount,
79+
int(
80+
math.ceil(
81+
(peak_height - peak_adjacent) * basin_width / (basin_width + 1)
82+
)
83+
)
84+
)
6685

6786
all_fill, extra = divmod(fill_amount, basin_width)
6887
ducks[peak_idx] -= fill_amount
@@ -89,26 +108,15 @@ def solve(part: int, data: list[int]) -> int:
89108
ducks = data.copy()
90109
num = len(ducks) - 1
91110

92-
if True:
93-
start = time.perf_counter_ns()
94-
steps = 0
95-
while any(a > b for a, b in zip(ducks, ducks[1:])):
96-
steps += 1
97-
for i in range(num):
98-
if ducks[i] > ducks[i + 1]:
99-
ducks[i] -= 1
100-
ducks[i + 1] += 1
101-
end = time.perf_counter_ns()
102-
brute = end - start
103-
start = time.perf_counter_ns()
104-
got_steps, got_ducks = experiment2(data)
105-
end = time.perf_counter_ns()
106-
flow = end - start
107-
else:
108-
steps, ducks = experiment2(data)
111+
steps = 0
112+
while any(a > b for a, b in zip(ducks, ducks[1:])):
113+
steps += 1
114+
for i in range(num):
115+
if ducks[i] > ducks[i + 1]:
116+
ducks[i] -= 1
117+
ducks[i + 1] += 1
109118

110119
if part > 1:
111-
assert ducks == sorted(ducks)
112120
average = sum(ducks) // len(ducks)
113121
return steps + sum(abs(i - average) for i in ducks) // 2
114122

@@ -122,32 +130,9 @@ def solve(part: int, data: list[int]) -> int:
122130

123131
PARSER = parsers.parse_one_int_per_line
124132
TEST_DATA = [
125-
"""\
126-
9
127-
1
128-
1
129-
4
130-
9
131-
6""",
132-
"""\
133-
9
134-
1
135-
1
136-
4
137-
9
138-
6""",
139-
"""\
140-
805
141-
706
142-
179
143-
48
144-
158
145-
150
146-
232
147-
885
148-
598
149-
524
150-
423""",
133+
"9 1 1 4 9 6".replace(" ", "\n"),
134+
"9 1 1 4 9 6".replace(" ", "\n"),
135+
"805 706 179 48 158 150 232 885 598 524 423".replace(" ", "\n"),
151136
]
152137
TESTS = [
153138
(1, TEST_DATA[0], 109),

everybody_codes/event2025/quest_12.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
import functools
44
import logging
5-
import time
65
from lib import helpers
76
from lib import parsers
87

0 commit comments

Comments
 (0)