AdventOfCode/2022/day8/day8_part1.py

59 lines
2.9 KiB
Python

import sys
from pprint import pprint
with open('test_input','r') as f:
lines = [[tree for tree in lines.rstrip('\n')] for lines in f]
forrest = [['O' for i in range(len(lines))] for j in range(len(lines[0]))]
for i in range(0,len(lines)):
for j in range(0,len(lines[i])):
forrest[i][j] = 'O'
for i in range(0,len(lines)):
for j in range(0,len(lines[i])):
print(lines[i][j],end='')
print('(' + str(i) + ',' + str(j)+ ') ',end='')
print()
for i in range(0,len(lines)):
for j in range(0,len(lines[i])):
#print(lines[i][j],end='')
#print('(' + str(i) + ',' + str(j)+ ') ',end='')
if (i > 0 and i < len(lines)-1) and (j > 0 and j < len(lines[i])-1):
#check up
print('-> Checking: ' + str(lines[i][j]) + '(' + str(i) + ',' + str(j) + ')')
for l in range(0,i): #check up
if forrest[i][j] == 'X':
break
#print('Range (up) : ' + forrest[i][j] +'>> ' + '0-' + str(i-1) + ' - ' + str(lines[i][j]) + '(' + str(i) + ',' + str(j)+ ')' + ' <=> ' + str(lines[l][j]) + '(' + str(l) + ',' + str(j)+ ') ')
if (lines[i][j] <= lines[l][j]) and forrest[i][j] != 'X':
for k in range(0,j): #check left
if forrest[i][j] == 'X':
break
#print('Range (left): ' + forrest[i][j] +'>> ' + '0-' + str(j-1) + ' - ' + str(lines[i][j]) + '(' + str(i) + ',' + str(j)+ ')' + ' <=> ' + str(lines[i][k]) + '(' + str(i) + ',' + str(k)+ ') ')
if lines[i][j] <= lines[i][k] and forrest[i][j] != 'X':
for p in range(i+1,len(lines)): #check down
if forrest[i][j] == 'X':
break
#print('Range (down): ' + forrest[i][j] +'>> ' + str(i+1) + '-' + str(len(lines)) + ' - ' + str(lines[i][j]) + '(' + str(i) + ',' + str(j)+ ')' + ' <=> ' + str(lines[p][j]) + '(' + str(p) + ',' + str(j)+ ') ')
if lines[i][j] <= lines[p][j] and forrest[i][j] != 'X':
for q in range(j+1,len(lines[0])): #check right
if forrest[i][j] == 'X':
break
#print('Range (right): ' + forrest[i][j] + '>> ' + str(j+1) + '-' + str(len(lines[0])) + ' - ' + str(lines[i][j]) + '(' + str(i) + ',' + str(j)+ ')' + ' <=> ' + str(lines[i][q]) + '(' + str(i) + ',' + str(q)+ ') ')
if lines[i][j] <= lines[i][q] and forrest[i][j] != 'X':
forrest[i][j] = 'X'
#print('adding X')
count=0
for i in forrest:
for j in i:
if j == 'O':
count+=1
print(count)