Compare commits
No commits in common. "21944b2c8f61b8caf0d1a51cfd6d6b47325f1805" and "8544896239cd3db2354a00c07c2f7a9284fac540" have entirely different histories.
21944b2c8f
...
8544896239
@ -3,9 +3,6 @@ import os
|
|||||||
from pprint import pprint
|
from pprint import pprint
|
||||||
import time
|
import time
|
||||||
import math
|
import math
|
||||||
import numpy as np
|
|
||||||
|
|
||||||
#21275 too low
|
|
||||||
|
|
||||||
#colors
|
#colors
|
||||||
from termcolor import colored
|
from termcolor import colored
|
||||||
@ -24,13 +21,7 @@ def p(x,*args):
|
|||||||
print()
|
print()
|
||||||
|
|
||||||
|
|
||||||
input_f = ''
|
with open(sys.argv[1]) as file:
|
||||||
if len(sys.argv) == 1:
|
|
||||||
input_f = 'test'
|
|
||||||
else:
|
|
||||||
input_f = sys.argv[1]
|
|
||||||
|
|
||||||
with open(input_f) as file:
|
|
||||||
for line in file:
|
for line in file:
|
||||||
grid.append(list(line.rstrip()))
|
grid.append(list(line.rstrip()))
|
||||||
|
|
||||||
@ -44,48 +35,17 @@ def rotate_grid(grid,times):
|
|||||||
p(grid)
|
p(grid)
|
||||||
return grid
|
return grid
|
||||||
|
|
||||||
def find_sym_col(grid):
|
def find_sym(grid):
|
||||||
mirror = 0
|
mirror = 0
|
||||||
found = False
|
found = False
|
||||||
|
|
||||||
for c,col in enumerate(grid):
|
for c,col in enumerate(grid):
|
||||||
if c+1 < len(col) and not found:
|
if c+1 < len(col) and not found:
|
||||||
#print('Testing columns' + str(c))
|
|
||||||
mirror_count = 0
|
|
||||||
for i in range(len(grid)):
|
|
||||||
#print(grid[i][c],grid[i][c+1],end='')
|
|
||||||
if grid[i][c] == grid[i][c+1]:
|
|
||||||
mirror_count += 1
|
|
||||||
#print('match')
|
|
||||||
#else:
|
|
||||||
#print('not match')
|
|
||||||
# break
|
|
||||||
|
|
||||||
if mirror_count == len(grid):
|
|
||||||
found = True
|
|
||||||
print('mirror at ' + str(c))
|
|
||||||
for x in range(c,-1,-1):
|
|
||||||
if (c-x)+c+1 < len(col):
|
|
||||||
#print(x,(c-x)+c+1)
|
|
||||||
mirror = False
|
|
||||||
for y in range(len(grid)):
|
|
||||||
if grid[y][x] == grid[y][(c-x)+c+1]:
|
|
||||||
#print(grid[y][x],grid[y][(c-x)+c+1])
|
|
||||||
mirror = c+1
|
|
||||||
found = True
|
|
||||||
else:
|
|
||||||
found = False
|
|
||||||
if found:
|
|
||||||
return mirror
|
|
||||||
else:
|
|
||||||
return None
|
|
||||||
|
|
||||||
|
|
||||||
def find_sym_row(grid):
|
|
||||||
mirror = 0
|
|
||||||
found = False
|
|
||||||
for r,row in enumerate(grid):
|
for r,row in enumerate(grid):
|
||||||
if r+1 < len(grid) and not found:
|
if r+1 < len(grid) and not found:
|
||||||
#print('testing rows' + str(r))
|
print('testing ' + str(r))
|
||||||
if grid[r] == grid[r+1]:
|
if grid[r] == grid[r+1]:
|
||||||
for c in range(r,-1,-1):
|
for c in range(r,-1,-1):
|
||||||
if (r-c)+r+1 < len(grid):
|
if (r-c)+r+1 < len(grid):
|
||||||
@ -93,38 +53,16 @@ def find_sym_row(grid):
|
|||||||
found = True
|
found = True
|
||||||
mirror = r+1
|
mirror = r+1
|
||||||
else:
|
else:
|
||||||
found = False
|
|
||||||
return None
|
return None
|
||||||
if found:
|
return mirror
|
||||||
return mirror
|
|
||||||
else:
|
|
||||||
return None
|
|
||||||
|
|
||||||
tmp = []
|
tmp = []
|
||||||
|
|
||||||
|
|
||||||
def find_sym(grid):
|
|
||||||
p(grid)
|
|
||||||
t = find_sym_col(grid)
|
|
||||||
if t == None:
|
|
||||||
return find_sym_row(grid), 'r'
|
|
||||||
else:
|
|
||||||
return t,'c'
|
|
||||||
|
|
||||||
|
|
||||||
result = 0
|
|
||||||
for i in grid:
|
for i in grid:
|
||||||
if i == []:
|
if i == []:
|
||||||
t = find_sym(tmp)
|
print('new grid')
|
||||||
print(t)
|
pprint(tmp)
|
||||||
#input()
|
print(find_sym(tmp))
|
||||||
if t[0] != None:
|
|
||||||
if t[1] == 'c':
|
|
||||||
result += t[0]
|
|
||||||
if t[1] == 'r':
|
|
||||||
result = result + (100*t[0])
|
|
||||||
tmp = []
|
tmp = []
|
||||||
else:
|
else:
|
||||||
tmp.append(i)
|
tmp.append(i)
|
||||||
|
|
||||||
print(result)
|
|
||||||
|
@ -1,40 +0,0 @@
|
|||||||
import sys
|
|
||||||
import os
|
|
||||||
from pprint import pprint
|
|
||||||
import time
|
|
||||||
import math
|
|
||||||
|
|
||||||
#colors
|
|
||||||
from termcolor import colored
|
|
||||||
|
|
||||||
grid = []
|
|
||||||
|
|
||||||
input_f = ''
|
|
||||||
if len(sys.argv) == 1:
|
|
||||||
input_f = 'test'
|
|
||||||
else:
|
|
||||||
input_f = sys.argv[1]
|
|
||||||
|
|
||||||
with open(input_f) as file:
|
|
||||||
for line in file:
|
|
||||||
grid = line.rstrip().split(',')
|
|
||||||
|
|
||||||
print(grid)
|
|
||||||
values = []
|
|
||||||
current_value = 0
|
|
||||||
|
|
||||||
for i in grid:
|
|
||||||
value = 0
|
|
||||||
for j in list(i):
|
|
||||||
current_value += value
|
|
||||||
#print(j)
|
|
||||||
current_value += ord(j)
|
|
||||||
current_value *= 17
|
|
||||||
current_value %= 256
|
|
||||||
#print(current_value)
|
|
||||||
value = current_value
|
|
||||||
current_value = 0
|
|
||||||
print(value)
|
|
||||||
values.append(value)
|
|
||||||
|
|
||||||
print(sum(values))
|
|
Loading…
Reference in New Issue
Block a user