From 811f0609cbec2e82d4f5a903f79f8ac1a28f4557 Mon Sep 17 00:00:00 2001 From: FrederikBaerentsen Date: Mon, 11 Dec 2023 22:29:59 +0100 Subject: [PATCH] Finished 2023-12-11 p1 --- 2023/day11/part1.py | 31 +++++++++++++++++++++++++++---- 1 file changed, 27 insertions(+), 4 deletions(-) diff --git a/2023/day11/part1.py b/2023/day11/part1.py index b0e85ca..e189a18 100644 --- a/2023/day11/part1.py +++ b/2023/day11/part1.py @@ -2,6 +2,7 @@ import sys import os from pprint import pprint import time +import math #colors from termcolor import colored @@ -32,10 +33,7 @@ def expand_galaxy(grid): ngrid=[] for r,row in enumerate(grid): if not '#' in row: - tmp = [] - for i in range(len(grid[0])): - tmp.append('.') - ngrid.append(tmp) + ngrid.append(row) ngrid.append(row) return ngrid @@ -50,3 +48,28 @@ grid = rotate_galaxy(grid,1) grid = expand_galaxy(grid) grid = rotate_galaxy(grid,3) p(grid) + +galaxies = [] +for r,row in enumerate(grid): + for c,col in enumerate(row): + if grid[r][c] == '#': + galaxies.append((r,c)) + +count = 0 +checked = 0 +skip = [] +for gdx,g in enumerate(galaxies): + for pdx,p in enumerate(galaxies): + if g != p and (g,p) not in skip: + print(checked,end='') + print(' of ',end='') + print(len(galaxies)*len(galaxies)/2) + skip.append((g,p)) + skip.append((p,g)) + checked += 1 + d = abs(list(g)[0] - list(p)[0]) + abs(list(g)[1]-list(p)[1]) + #d = math.dist(g,p) + count += d + #print('Distance between galaxy ' + str(gdx+1) + ' ' + str(g) + ' and ' + str(pdx+1) + ' ' + str(p) + ' is ' + str(d)) +print(checked) +print(count)