From 788c45edb7943905fcd912734af18211b69347bb Mon Sep 17 00:00:00 2001 From: setop Date: Wed, 11 Dec 2024 12:31:25 +0100 Subject: [PATCH] day 8, refactor using grid lib --- d08/run.py | 24 +++++------------------- 1 file changed, 5 insertions(+), 19 deletions(-) diff --git a/d08/run.py b/d08/run.py index 361b731..cfae55e 100644 --- a/d08/run.py +++ b/d08/run.py @@ -1,27 +1,13 @@ import sys, os from collections import defaultdict as dd from itertools import combinations as comb - -def grid_geom(G): - H = len(G) - W = len(G[0]) - return W, H - -def in_grid(G, x, y) -> bool: - W, H = grid_geom(G) - return x>=0 and x=0 and y1 and sys.argv[1]=="2" else [1] -L = sys.stdin.read().strip().split("\n") -G = [list(l) for l in L] +G = [list(l) for l in sys.stdin.read().strip().split("\n")] - -# dico of position +# dict of antenna's position grouped by freq P = dd(list) W, H = grid_geom(G) for y in range(H): # rows @@ -31,8 +17,8 @@ for y in range(H): # rows P[v].append((x, y)) A = set() # antinodes -for k,v in P.items(): - for a,b in comb(v,2): +for _,v in P.items(): + for a,b in comb(v,2): # for each pair of antenna resonating x1, y1 = a x2, y2 = b dx = x2 - x1