From f14630b3e4495d2fa373fba076329f2e3b169a56 Mon Sep 17 00:00:00 2001 From: FrederikBaerentsen Date: Sun, 3 Dec 2023 15:21:06 +0100 Subject: [PATCH] Finding neighbor numbers --- 2023/day3/part1/part1.py | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/2023/day3/part1/part1.py b/2023/day3/part1/part1.py index 1c58f86..cd173f2 100644 --- a/2023/day3/part1/part1.py +++ b/2023/day3/part1/part1.py @@ -30,15 +30,25 @@ for idx,i in enumerate(arr): for jdx,j in enumerate(i): tmp = arr[idx][jdx] if tmp.isdigit() == False and tmp != '.': - print(tmp) - print(idx,jdx) + print(tmp + " (" + str(idx) + "," + str(jdx) + ")") -n = neighbors(4,2) - -pprint(n) +n = neighbors(1,3) for i in n: - print(i) - print(arr[i[0]][i[1]]) + 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()