Skip to content

Commit 8f91817

Browse files
authored
Run lints
Signed-off-by: GitHub <[email protected]>
1 parent cc3d3c3 commit 8f91817

File tree

5 files changed

+21
-28
lines changed

5 files changed

+21
-28
lines changed

.pre-commit-config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
repos:
22
- repo: https://github.com/pre-commit/pre-commit-hooks
3-
rev: v4.4.0
3+
rev: v5.0.0
44
hooks:
55
- id: check-case-conflict
66
- id: check-merge-conflict

events/advent_of_code/2024/02/python/aoc_2024_01.py

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
import collections
2+
from collections.abc import Generator, Iterable
23
from dataclasses import dataclass
34
from itertools import islice
45
from pathlib import Path
6+
from typing import Any
57

68

7-
def sliding_window(iterable, n):
9+
def sliding_window(iterable: Iterable, n: int) -> Generator[tuple[Any, ...]]:
810
"""Collect data into overlapping fixed-length chunks or blocks."""
911
# sliding_window('ABCDEFG', 4) → ABCD BCDE CDEF DEFG
1012
iterator = iter(iterable)
@@ -18,34 +20,30 @@ def sliding_window(iterable, n):
1820
class Report:
1921
values: list[int]
2022

21-
def is_safe(self, dampener_enabled: bool = False) -> bool:
23+
def is_safe(self, *, dampener_enabled: bool = False) -> bool:
2224
dampener_used = False
2325

24-
increasing_changes = sum(1 for left, right in zip(self.values, self.values[1:]) if left > right)
25-
print(f"{increasing_changes=}")
26+
increasing_changes = sum(1 for left, right in zip(self.values, self.values[1:], strict=False) if left > right)
2627
if dampener_enabled and not dampener_used and increasing_changes == 1:
2728
dampener_used = True
2829
increasing_changes -= 1
2930
all_increasing = increasing_changes == 0
30-
print(f"{all_increasing=}")
3131

32-
decreasing_changes = sum(1 for left, right in zip(self.values, self.values[1:]) if left < right)
33-
print(f"{decreasing_changes=}")
32+
decreasing_changes = sum(1 for left, right in zip(self.values, self.values[1:], strict=False) if left < right)
3433
if dampener_enabled and not dampener_used and decreasing_changes == 1:
3534
dampener_used = True
3635
decreasing_changes -= 1
3736
all_decreasing = decreasing_changes == 0
38-
print(f"{all_decreasing=}")
3937

4038
unsafe_values = 0
4139
for left, right in sliding_window(self.values, 2):
4240
print(f"{left=}, {right=}, {abs(left - right)=}")
43-
if not 1 <= abs(left - right) <= 3:
41+
if not 1 <= abs(left - right) <= 3:
4442
unsafe_values += 1
4543
print(f"{unsafe_values=}")
4644
if dampener_enabled and not dampener_used and unsafe_values == 1:
4745
dampener_used = True
48-
unsafe_values -= 1
46+
unsafe_values -= 1
4947
within_boundaries = unsafe_values == 0
5048
print(f"{within_boundaries=}")
5149

events/advent_of_code/2024/02/python/test_aoc_2024_01.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,10 @@
1313
([1, 3, 6, 7, 9], True),
1414
],
1515
)
16-
def test_report_is_safe(values: list[int], is_safe: bool) -> None:
16+
def test_report_is_safe(values: list[int], is_safe: bool) -> None: # noqa: FBT001
1717
assert Report(values).is_safe() == is_safe
1818

19+
1920
@pytest.mark.parametrize(
2021
("values", "is_safe"),
2122
[
@@ -27,5 +28,5 @@ def test_report_is_safe(values: list[int], is_safe: bool) -> None:
2728
([1, 3, 6, 7, 9], True),
2829
],
2930
)
30-
def test_report_is_safe_wth_dampener(values: list[int], is_safe: bool) -> None:
31+
def test_report_is_safe_wth_dampener(values: list[int], is_safe: bool) -> None: # noqa: FBT001
3132
assert Report(values).is_safe(dampener_enabled=True) == is_safe

events/advent_of_code/2024/04/python/aoc_2024_04.py

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
1-
import re
2-
from math import prod
31
from pathlib import Path
42

5-
63
LEFT_OFFSETS = [(0, -1), (0, -2), (0, -3), (0, -4)]
74
RIGHT_OFFSETS = [(0, 1), (0, 2), (0, 3), (0, 4)]
85
UP_OFFSETS = [(-1, 0), (-2, 0), (-3, 0), (-4, 0)]
@@ -25,28 +22,29 @@
2522
"diagonal_right_down": DIAGONAL_RIGHT_DOWN_OFFSETS,
2623
}
2724

25+
2826
def part1(text: str) -> int:
2927
text = text.lstrip("\n").rstrip("\n")
3028
count = 0
3129
grid = [list(line) for line in text.split("\n")]
3230
height = len(grid)
3331
width = len(grid[0])
34-
for y in range(height):
32+
for y in range(height): # noqa: PLR1702
3533
for x in range(width):
36-
print(f"Checking {y}, {x}, {grid[y][x]}")
34+
print(f"Checking {y}, {x}, {grid[y][x]}")
3735
if grid[y][x] == "X":
38-
for offset_name,offsets in OFFSETS.items():
36+
for offset_name, offsets in OFFSETS.items():
3937
try:
40-
if "".join([grid[y + offset[0]][x + offset[1]] for offset in offsets]) == "XMAS":
41-
count += 1
42-
print(f"Found XMAS at {y}, {x}, {offset_name}")
38+
if "".join([grid[y + offset[0]][x + offset[1]] for offset in offsets]) == "XMAS":
39+
count += 1
40+
print(f"Found XMAS at {y}, {x}, {offset_name}")
4341
except IndexError:
4442
continue
4543
return count
4644

4745

4846
def part2(text: str) -> int:
49-
return 0
47+
return len(text)
5048

5149

5250
if __name__ == "__main__":

scratch/games/the-farmer-was-replaced/code.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -60,11 +60,7 @@ def tplace() -> bool | None:
6060
if get_water() < 0.5:
6161
use_item(Items.Water_Tank)
6262

63-
elif (
64-
get_ground_type() == Grounds.soil
65-
and get_entity_type() == Entities.Carrots
66-
and can_harvest() is True
67-
):
63+
elif get_ground_type() == Grounds.soil and get_entity_type() == Entities.Carrots and can_harvest() is True:
6864
harvest()
6965
trade(Items.Carrot_Seed)
7066
plant(Entities.Carrots)

0 commit comments

Comments
 (0)