Finished 2023-12-11 p1
This commit is contained in:
parent
8049c42fa3
commit
811f0609cb
@ -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)
|
||||
|
Loading…
Reference in New Issue
Block a user