59 lines
2.8 KiB
Python
59 lines
2.8 KiB
Python
import sys
|
|
|
|
from pprint import pprint
|
|
|
|
with open(sys.argv[1],'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
|
|
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 forrest[i][j] == 'X':
|
|
break
|
|
if (lines[i][j] <= lines[l][j]):
|
|
for k in range(0,j): #check left
|
|
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 forrest[i][j] == 'X':
|
|
break
|
|
if lines[i][j] <= lines[i][k]:
|
|
for p in range(i+1,len(lines)): #check down
|
|
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 forrest[i][j] == 'X':
|
|
break
|
|
if lines[i][j] <= lines[p][j]:
|
|
for q in range(j+1,len(lines[0])): #check right
|
|
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 forrest[i][j] == 'X':
|
|
break
|
|
if lines[i][j] <= lines[i][q]:
|
|
forrest[i][j] = 'X'
|
|
#print('adding X')
|
|
|
|
|
|
count=0
|
|
|
|
for i in forrest:
|
|
for j in i:
|
|
if j == 'O':
|
|
count+=1
|
|
print(count)
|