Partial solution of intermediate card
This commit is contained in:
parent
6a263ab1b1
commit
af3b8d52e3
26
18/24.py
Normal file
26
18/24.py
Normal file
@ -0,0 +1,26 @@
|
||||
inf = float('inf')
|
||||
|
||||
|
||||
def count(a: list[list[int]], i: int, j: int) -> list[int]:
|
||||
if a[i][j] > 100 and a[i][j] < 500 or a[i][j] < 0 and a[i][j] > -400:
|
||||
return [0, inf]
|
||||
|
||||
t, l = [0, inf], [0, inf]
|
||||
summ = a[i][j]
|
||||
|
||||
if i > 0:
|
||||
t = count(a, i-1, j)
|
||||
if j > 0:
|
||||
l = count(a, i, j-1)
|
||||
|
||||
# minn = min(t[1], l[1])
|
||||
|
||||
return [summ + max(t[0], l[0]), summ + min(t[1], l[1])]
|
||||
|
||||
|
||||
with open("dat/18-13.csv", 'r') as f:
|
||||
a = [[int(i) for i in row.split(';')] for row in f.readlines()]
|
||||
|
||||
print(count(a, len(a) - 1, len(a[0]) - 1))
|
||||
|
||||
# 1535
|
14
18/40.py
Normal file
14
18/40.py
Normal file
@ -0,0 +1,14 @@
|
||||
with open('dat/18-k1.csv', "r") as f:
|
||||
k = 0
|
||||
m = 0
|
||||
for i in f.readlines():
|
||||
if int(i) % 2 == 1:
|
||||
k += 1
|
||||
else:
|
||||
if k > m:
|
||||
m = k
|
||||
k = 0
|
||||
|
||||
print(m)
|
||||
|
||||
# 5
|
11
18/44.py
Normal file
11
18/44.py
Normal file
@ -0,0 +1,11 @@
|
||||
a = [int(i) for i in open('dat/18-k3.csv', 'r')]
|
||||
|
||||
k = 0
|
||||
for i in range(len(a) - 5):
|
||||
for j in range(1, 6):
|
||||
if a[i] + a[j] < 100:
|
||||
k += 1
|
||||
|
||||
print(k)
|
||||
|
||||
# 15
|
25
18/69.py
Normal file
25
18/69.py
Normal file
@ -0,0 +1,25 @@
|
||||
def count(a, i, j):
|
||||
if i == -1 or j == -1:
|
||||
return None
|
||||
|
||||
l = count(a, i, j-1)
|
||||
t = count(a, i-1, j)
|
||||
c = a[i][j] // 8
|
||||
|
||||
if l == None and t == None:
|
||||
return [c, c]
|
||||
if l == None:
|
||||
return [c + t[0], c + t[1]]
|
||||
if t == None:
|
||||
return [c + l[0], c + l[1]]
|
||||
|
||||
return [c + max(t[0], l[0]), c + min(t[1], l[1])]
|
||||
|
||||
|
||||
a = [[int(i) for i in row.split(';')] for row in open('dat/18-2.csv', 'r')]
|
||||
|
||||
res = count(a, len(a)-1, len(a[0])-1)
|
||||
|
||||
print(res[0] * 8, res[1] * 8)
|
||||
|
||||
# 1256 472
|
29
18/73.py
Normal file
29
18/73.py
Normal file
@ -0,0 +1,29 @@
|
||||
def count(a, i, j):
|
||||
if i == len(a)-1:
|
||||
return [a[i][j], a[i][j]]
|
||||
|
||||
M, m = count(a, i+1, j)
|
||||
|
||||
res1, res2 = [M, m], [M, m]
|
||||
|
||||
if j > 0:
|
||||
res1 = count(a, i+1, j-1)
|
||||
|
||||
if j < len(a[0])-1:
|
||||
res2 = count(a, i+1, j+1)
|
||||
|
||||
return a[i][j] + max(M, res1[0], res2[0]), a[i][j] + min(m, res1[1], res2[1])
|
||||
|
||||
|
||||
a = [[int(i) for i in row.split(';')] for row in open('dat/18-0.csv', 'r')]
|
||||
|
||||
M, m = 0, float('inf')
|
||||
|
||||
for i in range(len(a[0])):
|
||||
res = count(a, 0, i)
|
||||
M = max(M, res[0])
|
||||
m = min(m, res[1])
|
||||
|
||||
print(M, m)
|
||||
|
||||
# 811 201
|
29
18/74.py
Normal file
29
18/74.py
Normal file
@ -0,0 +1,29 @@
|
||||
def count(a, i, j):
|
||||
if j == len(a[0])-1:
|
||||
return [a[i][j], a[i][j]]
|
||||
|
||||
M, m = count(a, i, j+1)
|
||||
|
||||
res1, res2 = [M, m], [M, m]
|
||||
|
||||
if i > 0:
|
||||
res1 = count(a, i-1, j+1)
|
||||
|
||||
if i < len(a)-1:
|
||||
res2 = count(a, i+1, j+1)
|
||||
|
||||
return a[i][j] + max(M, res1[0], res2[0]), a[i][j] + min(m, res1[1], res2[1])
|
||||
|
||||
|
||||
a = [[int(i) for i in row.split(';')] for row in open('dat/18-0.csv', 'r')]
|
||||
|
||||
M, m = 0, float('inf')
|
||||
|
||||
for i in range(len(a)):
|
||||
res = count(a, i, 0)
|
||||
M = max(M, res[0])
|
||||
m = min(m, res[1])
|
||||
|
||||
print(M, m)
|
||||
|
||||
# 785 176
|
Loading…
x
Reference in New Issue
Block a user