Initial release
This commit is contained in:
39
Il faut sauver Loïs.py
Normal file
39
Il faut sauver Loïs.py
Normal file
@@ -0,0 +1,39 @@
|
||||
input = """01 19 09 09 08 18 13 00 13 02 18 18 17 09 00
|
||||
16 01 10 08 06 16 16 18 14 18 15 17 20 15 17
|
||||
05 03 19 14 01 00 03 08 15 12 02 15 15 15 02
|
||||
08 20 07 20 06 14 12 04 03 07 19 11 15 08 08
|
||||
15 08 08 14 12 16 08 02 10 16 17 01 12 00 17
|
||||
00 12 18 13 01 03 02 17 10 07 04 15 19 08 13
|
||||
02 13 20 01 19 04 01 01 00 14 04 03 12 02 08
|
||||
11 03 02 20 09 15 01 18 14 13 02 03 17 13 20
|
||||
16 05 09 09 05 17 16 04 18 09 01 03 07 06 13
|
||||
17 17 01 06 10 03 15 13 07 01 09 10 09 18 13
|
||||
03 20 19 03 15 04 17 00 18 14 18 08 03 16 02
|
||||
07 03 05 14 00 08 06 03 04 13 03 10 15 13 14
|
||||
16 02 16 15 09 01 13 07 14 00 04 01 03 09 02
|
||||
03 03 04 17 12 12 20 05 19 14 06 04 14 05 11
|
||||
12 04 01 15 05 10 00 02 18 04 12 08 06 03 05"""
|
||||
|
||||
input = input.splitlines()
|
||||
table = [x.split() for x in input]
|
||||
|
||||
def min_matrix(matrix):
|
||||
if len(matrix) == 1 and len(matrix[0]) == 1:
|
||||
return int(matrix[0][0])
|
||||
|
||||
if len(matrix) > 1:
|
||||
matrix1 = matrix[1:]
|
||||
sum1 = int(matrix[0][0]) + min_matrix(matrix1)
|
||||
else:
|
||||
sum1 = 999999
|
||||
|
||||
if len(matrix[0]) > 1:
|
||||
matrix2 = [x[1:] for x in matrix]
|
||||
sum2 = int(matrix[0][0]) + min_matrix(matrix2)
|
||||
else:
|
||||
sum2 = 999999
|
||||
|
||||
return min(sum1, sum2)
|
||||
|
||||
sum=min_matrix(table)
|
||||
print(sum)
|
||||
Reference in New Issue
Block a user