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
@@ -2,7 +2,7 @@ from collections import Counter
|
||||
|
||||
|
||||
def main(lines):
|
||||
firsts, seconds = list(sorted(x[0] for x in lines)), list(sorted(x[1] for x in lines))
|
||||
firsts, seconds = sorted(x[0] for x in lines), sorted(x[1] for x in lines)
|
||||
total = sum(abs(a - b) for (a, b) in zip(firsts, seconds))
|
||||
print("Part 1: ", total)
|
||||
|
||||
|
||||
@@ -63,6 +63,6 @@ if __name__ == "__main__":
|
||||
import sys
|
||||
infile = sys.argv[1] if 1 < len(sys.argv) else "example.txt"
|
||||
with open(infile) as f:
|
||||
grid = [list(map(int, list(l.rstrip()))) for l in f.readlines()]
|
||||
grid = [list(map(int, list(l.rstrip()))) for l in f]
|
||||
main(grid)
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
from collections import Counter
|
||||
|
||||
|
||||
def main(data):
|
||||
part1 = run(data, 25)
|
||||
print("Part 1: ", part1)
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
from dataclasses import dataclass
|
||||
from collections import defaultdict
|
||||
|
||||
|
||||
@dataclass(frozen=True)
|
||||
@@ -78,6 +77,6 @@ if __name__ == "__main__":
|
||||
import sys
|
||||
infile = sys.argv[1] if 1 < len(sys.argv) else "example.txt"
|
||||
with open(infile) as f:
|
||||
grid = [l.rstrip() for l in f.readlines()]
|
||||
grid = [l.rstrip() for l in f]
|
||||
main(grid)
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
from math import prod
|
||||
from collections import Counter
|
||||
from math import prod
|
||||
|
||||
|
||||
def parse_bots(lines):
|
||||
|
||||
@@ -9,7 +9,7 @@ DIRECTIONS = {
|
||||
def find_start_pos(grid):
|
||||
for y, row in enumerate(grid):
|
||||
for x, _ in enumerate(row):
|
||||
if grid[y][x] == "@":
|
||||
if row[x] == "@":
|
||||
return complex(x, y)
|
||||
|
||||
|
||||
@@ -69,7 +69,7 @@ def calculate_gps_coords(grid):
|
||||
total = 0
|
||||
for y, row in enumerate(grid):
|
||||
for x, _ in enumerate(row):
|
||||
if grid[y][x] == "O":
|
||||
if row[x] == "O":
|
||||
total += 100*y + x
|
||||
return total
|
||||
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
from dataclasses import dataclass
|
||||
from heapq import heappop, heappush
|
||||
|
||||
|
||||
DIRECTIONS = {
|
||||
">": 1 + 0j, # EAST
|
||||
"v": 0 + 1j, # SOUTH
|
||||
@@ -27,9 +26,9 @@ def find_start_and_goal(grid):
|
||||
start, goal = None, None
|
||||
for y, row in enumerate(grid):
|
||||
for x, _ in enumerate(row):
|
||||
if grid[y][x] == "S":
|
||||
if row[x] == "S":
|
||||
start = complex(x, y)
|
||||
elif grid[y][x] == "E":
|
||||
elif row[x] == "E":
|
||||
goal = complex(x, y)
|
||||
return start, goal
|
||||
|
||||
@@ -112,6 +111,6 @@ if __name__ == "__main__":
|
||||
import sys
|
||||
infile = sys.argv[1] if 1 < len(sys.argv) else "example.txt"
|
||||
with open(infile) as f:
|
||||
grid = [list(l.rstrip()) for l in f.readlines()]
|
||||
grid = [list(l.rstrip()) for l in f]
|
||||
main(grid)
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
from dataclasses import dataclass
|
||||
from heapq import heappush, heappop
|
||||
|
||||
from heapq import heappop, heappush
|
||||
|
||||
DIRECTIONS = (
|
||||
1 + 0j, # EAST
|
||||
|
||||
@@ -47,16 +47,16 @@ def part2(grid):
|
||||
if grid[y+1][x+1] != "A": # center letter is always "A"
|
||||
continue
|
||||
# M.S / .A. / M.S
|
||||
if grid[y][x] == "M" and grid[y][x+2] == "S" and grid[y+2][x] == "M" and grid[y+2][x+2] == "S":
|
||||
if row[x] == "M" and row[x+2] == "S" and grid[y+2][x] == "M" and grid[y+2][x+2] == "S":
|
||||
count += 1
|
||||
# M.M / .A. / S.S
|
||||
if grid[y][x] == "M" and grid[y][x+2] == "M" and grid[y+2][x] == "S" and grid[y+2][x+2] == "S":
|
||||
if row[x] == "M" and row[x+2] == "M" and grid[y+2][x] == "S" and grid[y+2][x+2] == "S":
|
||||
count += 1
|
||||
# S.M / .A. / S.M
|
||||
if grid[y][x] == "S" and grid[y][x+2] == "M" and grid[y+2][x] == "S" and grid[y+2][x+2] == "M":
|
||||
if row[x] == "S" and row[x+2] == "M" and grid[y+2][x] == "S" and grid[y+2][x+2] == "M":
|
||||
count += 1
|
||||
# S.S / .A. / M.M
|
||||
if grid[y][x] == "S" and grid[y][x+2] == "S" and grid[y+2][x] == "M" and grid[y+2][x+2] == "M":
|
||||
if row[x] == "S" and row[x+2] == "S" and grid[y+2][x] == "M" and grid[y+2][x+2] == "M":
|
||||
count += 1
|
||||
print("Part 2: ", count)
|
||||
|
||||
@@ -66,7 +66,7 @@ if __name__ == "__main__":
|
||||
import sys
|
||||
infile = sys.argv[1] if 1 < len(sys.argv) else "example.txt"
|
||||
with open(infile) as f:
|
||||
grid = [l.rstrip() for l in f.readlines()]
|
||||
grid = [l.rstrip() for l in f]
|
||||
part1(grid)
|
||||
part2(grid)
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
from collections import defaultdict
|
||||
from itertools import pairwise
|
||||
|
||||
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
from itertools import cycle
|
||||
from dataclasses import dataclass
|
||||
from pprint import pprint
|
||||
from itertools import cycle
|
||||
|
||||
|
||||
@dataclass(frozen=True)
|
||||
@@ -75,6 +74,6 @@ if __name__ == "__main__":
|
||||
import sys
|
||||
infile = sys.argv[1] if 1 < len(sys.argv) else "example.txt"
|
||||
with open(infile) as f:
|
||||
grid = [list(l.rstrip()) for l in f.readlines()]
|
||||
grid = [list(l.rstrip()) for l in f]
|
||||
main(grid)
|
||||
|
||||
@@ -30,7 +30,7 @@ if __name__ == "__main__":
|
||||
import sys
|
||||
infile = sys.argv[1] if 1 < len(sys.argv) else "example.txt"
|
||||
with open(infile) as f:
|
||||
data = [l.rstrip().split(": ") for l in f.readlines()]
|
||||
data = [l.rstrip().split(": ") for l in f]
|
||||
data = [(int(a), tuple(map(int, b.split(" ")))) for a, b in data]
|
||||
main(data)
|
||||
|
||||
Reference in new issue
Block a user