53 lines
1.0 KiB
Python
53 lines
1.0 KiB
Python
|
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)
|