Starting on 2023-12-11 p1
This commit is contained in:
parent
b7d6046fc1
commit
8049c42fa3
52
2023/day11/part1.py
Normal file
52
2023/day11/part1.py
Normal file
@ -0,0 +1,52 @@
|
|||||||
|
import sys
|
||||||
|
import os
|
||||||
|
from pprint import pprint
|
||||||
|
import time
|
||||||
|
|
||||||
|
#colors
|
||||||
|
from termcolor import colored
|
||||||
|
|
||||||
|
grid = []
|
||||||
|
|
||||||
|
def p(x,*args):
|
||||||
|
for idx,i in enumerate(x):
|
||||||
|
for jdx,j in enumerate(i):
|
||||||
|
if j == '#':
|
||||||
|
print(colored(j,'red'),end='')
|
||||||
|
#elif (idx,jdx) in steps:
|
||||||
|
# print(colored(j,'green'),end='')
|
||||||
|
else:
|
||||||
|
print(j,end='')
|
||||||
|
print()
|
||||||
|
|
||||||
|
|
||||||
|
with open(sys.argv[1]) as file:
|
||||||
|
for line in file:
|
||||||
|
grid.append(list(line.rstrip()))
|
||||||
|
|
||||||
|
steps = []
|
||||||
|
|
||||||
|
ngrid = []
|
||||||
|
|
||||||
|
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)
|
||||||
|
return ngrid
|
||||||
|
|
||||||
|
def rotate_galaxy(grid,times):
|
||||||
|
for i in range(times):
|
||||||
|
grid = list(zip(*grid[::-1]))
|
||||||
|
return grid
|
||||||
|
|
||||||
|
p(grid)
|
||||||
|
grid = expand_galaxy(grid)
|
||||||
|
grid = rotate_galaxy(grid,1)
|
||||||
|
grid = expand_galaxy(grid)
|
||||||
|
grid = rotate_galaxy(grid,3)
|
||||||
|
p(grid)
|
Loading…
Reference in New Issue
Block a user