AdventOfCode/2023/day3/part1/part1.py

55 lines
1.3 KiB
Python
Raw Normal View History

2023-12-03 07:02:39 +01:00
#!/bin/python3
import re
import sys
from pprint import pprint
input_f = sys.argv[1]
count = 0
arr = []
with open(input_f) as file:
for line in file:
arr.append(list(line.lstrip().rstrip()))
pprint(arr)
X=len(arr[0])
Y=len(arr)
neighbors = lambda x, y : [(x2, y2) for x2 in range(x-1, x+2)
for y2 in range(y-1, y+2)
if (-1 < x <= X and
-1 < y <= Y and
(x != x2 or y != y2) and
(0 <= x2 <= X) and
(0 <= y2 <= Y))]
for idx,i in enumerate(arr):
for jdx,j in enumerate(i):
tmp = arr[idx][jdx]
if tmp.isdigit() == False and tmp != '.':
2023-12-03 15:21:06 +01:00
print(tmp + " (" + str(idx) + "," + str(jdx) + ")")
2023-12-03 15:21:06 +01:00
n = neighbors(1,3)
for i in n:
2023-12-03 15:21:06 +01:00
if arr[i[0]][i[1]].isdigit():
print(arr[i[0]][i[1]])
ctmp = 0
print(arr[i[0]][i[1]-ctmp])
while arr[i[0]][i[1]-ctmp].isdigit():
print("First neighbor ",end="")
print(arr[i[0]][i[1]-ctmp])
ctmp = ctmp + 1
#print(arr[i[0]][i[1]-ctmp])
#print(i)
#print(i[0])
#print(i[1]-1)
#print(arr[i[0]][i[1]-1])
print()
2023-12-03 07:02:39 +01:00