jour 3 j1 maj

This commit is contained in:
Arthur 2023-12-03 08:41:13 +01:00
parent 0cbabfa212
commit a4814502c4
1 changed files with 6 additions and 5 deletions

View File

@ -6,7 +6,7 @@ def if_symbol_adj(l, n, i):
for m in [n-1, n, n+1]: for m in [n-1, n, n+1]:
if m < 0 or m > len(l)-1: continue if m < 0 or m > len(l)-1: continue
for j in [i-1, i, i+1]: for j in [i-1, i, i+1]:
if j < 0 or j > len(l[m]): continue if j < 0 or j > len(l[m])-1: continue
if l[m][j] != "." and l[m][j].isdigit() is False: if l[m][j] != "." and l[m][j].isdigit() is False:
return True return True
else: else:
@ -23,10 +23,11 @@ def main(S = 0):
if myList[n][i].isdigit(): if myList[n][i].isdigit():
nb = "".join([nb, myList[n][i]]) nb = "".join([nb, myList[n][i]])
if_sum = if_sum or if_symbol_adj(myList, n, i) if_sum = if_sum or if_symbol_adj(myList, n, i)
else:
# soit pas encore un nombre soit la fin if not myList[n][i].isdigit() or i == len(myList[n]) -1:
print(int(nb), if_sum) # soit pas encore un nombre soit la fin d'un nombre, soit la fin d'une ligne
S += (int(nb) if nb != "" else 0) #if nb!="": print(nb, if_sum)
S += (int(nb) if nb != "" and if_sum else 0)
if_sum = False if_sum = False
nb = "" nb = ""