diff --git a/d03/exemple1.txt b/d03/exemple1.txt new file mode 100644 index 0000000..624ea4f --- /dev/null +++ b/d03/exemple1.txt @@ -0,0 +1,10 @@ +467..114.. +...*...... +..35..633. +......#... +617*...... +.....+.58. +..592..... +......755. +...$.*.... +.664.598.. \ No newline at end of file diff --git a/d03/exemple3.txt b/d03/exemple3.txt new file mode 100644 index 0000000..4525d47 --- /dev/null +++ b/d03/exemple3.txt @@ -0,0 +1,4 @@ +467..114.. +...*...... +..35..633. +......#... \ No newline at end of file diff --git a/d03/run1.py b/d03/run1.py new file mode 100644 index 0000000..f36cf16 --- /dev/null +++ b/d03/run1.py @@ -0,0 +1,36 @@ +import sys + +myList = list(list(map(str,s)) for s in sys.stdin.read().splitlines()) + +def if_symbol_adj(l, n, i): + for m in [n-1, n, n+1]: + if m < 0 or m > len(l)-1: continue + for j in [i-1, i, i+1]: + if j < 0 or j > len(l[m]): continue + if l[m][j] != "." and l[m][j].isdigit() is False: + return True + else: + pass + return False + +def main(S = 0): + # de haut en bas + for n in range(len(myList)): + nb = "" + if_sum = False + # de gauche à droite + for i in range(len(myList[n])): + if myList[n][i].isdigit(): + nb = "".join([nb, myList[n][i]]) + if_sum = if_sum or if_symbol_adj(myList, n, i) + else: + # soit pas encore un nombre soit la fin + print(int(nb), if_sum) + S += (int(nb) if nb != "" else 0) + if_sum = False + nb = "" + + return S + +if __name__ == '__main__': + print(main()) \ No newline at end of file