mirror of
https://github.com/thib8956/advent-of-code.git
synced 2026-11-27 00:46:34 +00:00
fix lint
This commit is contained in:
1 parent
0232b9326d
commit
5c3fb89870
50 files changed
+97
-117
No files matched your search
@@ -1,6 +1,5 @@
|
||||
from typing import Dict, List, Set, Tuple
|
||||
from dataclasses import dataclass
|
||||
from collections import defaultdict
|
||||
from dataclasses import dataclass
|
||||
from enum import Enum
|
||||
|
||||
|
||||
@@ -42,7 +41,7 @@ PIPES = {
|
||||
PIPES_REVERSE_LOOKUP = {v: k for k,v in PIPES.items()}
|
||||
|
||||
|
||||
def find_start_position(grid: List[str]) -> Vec2d:
|
||||
def find_start_position(grid: list[str]) -> Vec2d:
|
||||
for y, row in enumerate(grid):
|
||||
for x, c in enumerate(row):
|
||||
if c == "S":
|
||||
@@ -50,7 +49,7 @@ def find_start_position(grid: List[str]) -> Vec2d:
|
||||
raise RuntimeError("The start position was not found")
|
||||
|
||||
|
||||
def update_start_symbol(grid: List[str], start_pos: Vec2d):
|
||||
def update_start_symbol(grid: list[str], start_pos: Vec2d):
|
||||
"""
|
||||
Updates the map by replacing the start symbol "S" with its actual corresponding pipe
|
||||
"""
|
||||
@@ -82,7 +81,7 @@ def update_start_symbol(grid: List[str], start_pos: Vec2d):
|
||||
grid[start_pos.y] = grid[start_pos.y].replace("S", pipe)
|
||||
|
||||
|
||||
def parse_graph(grid: List[str]) -> Dict[Vec2d, List[Vec2d]]:
|
||||
def parse_graph(grid: list[str]) -> dict[Vec2d, list[Vec2d]]:
|
||||
graph = defaultdict(list)
|
||||
|
||||
for y, row in enumerate(grid):
|
||||
@@ -95,7 +94,7 @@ def parse_graph(grid: List[str]) -> Dict[Vec2d, List[Vec2d]]:
|
||||
return graph
|
||||
|
||||
|
||||
def traverse_graph(graph, start_pos) -> Tuple[int, Set[Vec2d]]:
|
||||
def traverse_graph(graph, start_pos) -> tuple[int, set[Vec2d]]:
|
||||
"""
|
||||
traverse the graph using BFS, return the path and the
|
||||
find the length of the longest path in the graph
|
||||
@@ -154,5 +153,5 @@ if __name__ == "__main__":
|
||||
infile = sys.argv[1]
|
||||
|
||||
with open(infile) as f:
|
||||
lines = [l.rstrip() for l in f.readlines()]
|
||||
lines = [l.rstrip() for l in f]
|
||||
main(lines)
|
||||
@@ -1,9 +1,9 @@
|
||||
from typing import Tuple, List, Set
|
||||
from dataclasses import dataclass
|
||||
|
||||
|
||||
@dataclass(frozen=True)
|
||||
class Item:
|
||||
pos: Tuple[int, int]
|
||||
pos: tuple[int, int]
|
||||
symbol: str
|
||||
|
||||
|
||||
@@ -12,8 +12,8 @@ def browse_schema(schema):
|
||||
buf = []
|
||||
max_row, max_col = len(schema), len(schema[0])
|
||||
|
||||
symbols: List[Tuple[Item, Set[Item]]] = []
|
||||
numbers: List[Item] = []
|
||||
symbols: list[tuple[Item, set[Item]]] = []
|
||||
numbers: list[Item] = []
|
||||
|
||||
for y in range(max_row):
|
||||
for x in range(max_col):
|
||||
@@ -61,13 +61,13 @@ def part2(symbols, numbers):
|
||||
|
||||
|
||||
|
||||
def is_engine_part(neighbors: List[Item]) -> bool:
|
||||
def is_engine_part(neighbors: list[Item]) -> bool:
|
||||
# get list of symbols (not '.', \n or a number)
|
||||
symbols = filter(lambda x: not x.symbol.isnumeric() and not x.symbol in (".", "\n"), neighbors)
|
||||
return next(symbols, None) is not None
|
||||
|
||||
|
||||
def get_neighbors(pos: Tuple[int, int], length: int, schema: List[List[str]]) -> List[Item]:
|
||||
def get_neighbors(pos: tuple[int, int], length: int, schema: list[list[str]]) -> list[Item]:
|
||||
x, y = pos
|
||||
start_x = x - length
|
||||
neighbors = [get_neighbors_of((x, y), schema) for x in range(start_x, x)]
|
||||
@@ -75,10 +75,10 @@ def get_neighbors(pos: Tuple[int, int], length: int, schema: List[List[str]]) -
|
||||
return neighbors
|
||||
|
||||
|
||||
def get_neighbors_of(pos: Tuple[int, int], schema: List[List[str]]) -> List[Item]:
|
||||
def get_neighbors_of(pos: tuple[int, int], schema: list[list[str]]) -> list[Item]:
|
||||
max_row, max_col = len(schema), len(schema[0])
|
||||
x, y = pos
|
||||
neighbors: List[Item] = []
|
||||
neighbors: list[Item] = []
|
||||
|
||||
# top
|
||||
if y-1 >= 0:
|
||||
@@ -112,5 +112,5 @@ if __name__ == "__main__":
|
||||
import sys
|
||||
infile = sys.argv[1]
|
||||
with open(infile) as f:
|
||||
schema = [[c for c in line] for line in f.readlines()]
|
||||
schema = [[c for c in line] for line in f]
|
||||
browse_schema(schema)
|
||||
@@ -27,8 +27,7 @@ def part2(sections):
|
||||
print(f"calculate_for_subseeds(subseeds len={len(subseeds)})")
|
||||
res = calculate_for_subseeds(subseeds, sections)
|
||||
mini = min(res)
|
||||
if mini < min_seed:
|
||||
min_seed = mini
|
||||
min_seed = min(min_seed, mini)
|
||||
|
||||
print(f"Part 2 {min_seed}")
|
||||
|
||||
@@ -58,8 +57,8 @@ def parse_input(infile):
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
import sys
|
||||
import os
|
||||
import sys
|
||||
SCRIPTPATH = os.path.dirname(os.path.realpath(__file__))
|
||||
|
||||
infile = next(iter(sys.argv[1:]), None)
|
||||
|
||||
@@ -10,7 +10,7 @@ def calculate_wins(data):
|
||||
total = 1
|
||||
for time, record in data:
|
||||
ways = 0
|
||||
for n in range(0, time+1):
|
||||
for n in range(time+1):
|
||||
speed = n
|
||||
distance = (time-n) * speed
|
||||
if distance > record:
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
import re
|
||||
import math
|
||||
import re
|
||||
from itertools import cycle
|
||||
|
||||
|
||||
def parse_input(infile):
|
||||
with open(infile) as f:
|
||||
content = f.read().rstrip()
|
||||
@@ -63,8 +64,8 @@ def part2(directions, nodes):
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
import sys
|
||||
import os
|
||||
import sys
|
||||
SCRIPTPATH = os.path.dirname(os.path.realpath(__file__))
|
||||
infile = sys.argv[1] if len(sys.argv) == 2 else "example.txt"
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
def parse_input(infile):
|
||||
with open(infile) as f:
|
||||
return [[int(x) for x in l.strip().split()] for l in f.readlines()]
|
||||
return [[int(x) for x in l.strip().split()] for l in f]
|
||||
|
||||
|
||||
def process_line(line):
|
||||
@@ -25,8 +25,8 @@ def solve(data):
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
import sys
|
||||
import os
|
||||
import sys
|
||||
SCRIPTPATH = os.path.dirname(os.path.realpath(__file__))
|
||||
infile = sys.argv[1] if len(sys.argv) == 2 else "example.txt"
|
||||
data = parse_input(os.path.join(SCRIPTPATH, infile))
|
||||
|
||||
Reference in new issue
Block a user