Compare commits

...

3 Commits

Author SHA1 Message Date
21944b2c8f Finished 2023-12-15 p1 2023-12-15 14:38:52 -05:00
57c165da42 Working on 2023-12-13 p1 2023-12-15 14:11:48 -05:00
8bc7688e6c Working on 2023-12-13 p1 2023-12-15 13:45:31 -05:00
2 changed files with 110 additions and 8 deletions

View File

@ -3,6 +3,9 @@ import os
from pprint import pprint
import time
import math
import numpy as np
#21275 too low
#colors
from termcolor import colored
@ -21,7 +24,13 @@ def p(x,*args):
print()
with open(sys.argv[1]) as file:
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.append(list(line.rstrip()))
@ -35,17 +44,48 @@ def rotate_grid(grid,times):
p(grid)
return grid
def find_sym(grid):
def find_sym_col(grid):
mirror = 0
found = False
for c,col in enumerate(grid):
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):
if r+1 < len(grid) and not found:
print('testing ' + str(r))
#print('testing rows' + str(r))
if grid[r] == grid[r+1]:
for c in range(r,-1,-1):
if (r-c)+r+1 < len(grid):
@ -53,16 +93,38 @@ def find_sym(grid):
found = True
mirror = r+1
else:
found = False
return None
return mirror
if found:
return mirror
else:
return None
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:
if i == []:
print('new grid')
pprint(tmp)
print(find_sym(tmp))
t = find_sym(tmp)
print(t)
#input()
if t[0] != None:
if t[1] == 'c':
result += t[0]
if t[1] == 'r':
result = result + (100*t[0])
tmp = []
else:
tmp.append(i)
print(result)

40
2023/day15/part1.py Normal file
View File

@ -0,0 +1,40 @@
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))