diff --git a/18/1.py b/18/1.py index c302ddf..ba9ccf0 100644 --- a/18/1.py +++ b/18/1.py @@ -17,16 +17,6 @@ with open('./dat/18-6.txt', 'r') as f: new_row.append(ns) arr.append(new_row) -# for row in matrix: -# for el in row: -# print(el, end=' ') -# print() - -# print("-------------------------Delimeter-------------------------") - -# for row in arr: -# for el in row: -# print(el, end=' ') -# print() - print(arr[-1][-1]) + +# 1418 743 \ No newline at end of file diff --git a/18/24.py b/18/24.py index e10e692..5c66e58 100644 --- a/18/24.py +++ b/18/24.py @@ -1,26 +1,29 @@ -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 == len(a) or j == len(a[0]): + return None - if i > 0: - t = count(a, i-1, j) - if j > 0: - l = count(a, i, j-1) + if (a[i][j] > 100 and a[i][j] < 500) or (a[i][j] > -400 and a[i][j] < 0): + return None - # minn = min(t[1], l[1]) + r = count(a, i, j+1) + b = count(a, i+1, j) - return [summ + max(t[0], l[0]), summ + min(t[1], l[1])] + c = a[i][j] + + if r == None and b == None: + return [c, c] + if r == None: + return [c + b[0], c + b[1]] + if b == None: + return [c + r[0], c + r[1]] + + return [c + max(r[0], b[0]), c + min(r[1], b[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)) + print(count(a, 0, 0)) -# 1535 +# 1535 330 (не знаю как починить с минимумом) diff --git a/18/29.py b/18/29.py index 01302fd..2244605 100644 --- a/18/29.py +++ b/18/29.py @@ -10,10 +10,7 @@ def add_10(matrix, x, y, dir): return 0 -# n = int(input()) - with open('./dat/18-J5.csv', 'r', encoding='utf-8-sig') as f: - # with open('./input.txt', 'r') as f: matrix = [[len(i.strip()) and int(i) for i in l.split(';')] for l in f.readlines()] arr = [] @@ -33,16 +30,4 @@ with open('./dat/18-J5.csv', 'r', encoding='utf-8-sig') as f: new_row.append(ns) arr.append(new_row) -for row in matrix: - for el in row: - print(el, end=' ') - print() - -print("****************************Delimeter****************************") - -for row in arr: - for el in row: - print(el, end=' ') - print() - print(arr[-1][-1]) diff --git a/18/36.cpp b/18/36.cpp index 8604c0d..ff3b70b 100644 --- a/18/36.cpp +++ b/18/36.cpp @@ -3,6 +3,8 @@ using namespace std; +// 345 (Даже написал на плюсах, не знаю, что с ней не так) + int main() { ifstream inp("dat/18-17.txt"); diff --git a/18/36.py b/18/36.py index 0f913af..32cd2ef 100644 --- a/18/36.py +++ b/18/36.py @@ -1,4 +1,4 @@ -# 345 +# 345 (Даже написал на плюсах, не знаю, что с ней не так) with open('./dat/18-17.txt', 'r') as f: p = float('+inf') diff --git a/18/42.py b/18/42.py new file mode 100644 index 0000000..d76048b --- /dev/null +++ b/18/42.py @@ -0,0 +1,21 @@ +def count(a: list[list[int]], i: int, j: int, prev: int, n: int): + if j == n or i == n or j == -1 or i == -1 or a[i][j] <= prev: + return 0 + else: + summ = a[i][j] + + summ += max(count(a, i+1, j, a[i][j], n), count(a, i, j+1, a[i][j], n), + count(a, i-1, j, a[i][j], n), count(a, i, j-1, a[i][j], n)) + return summ + + +with open('dat/18-k2.csv', 'r') as f: + a = [[int(i) for i in row.split()] for row in f.readlines()] + m = 0 + for i in range(len(a)): + for j in range(len(a)): + m = max(m, count(a, i, j, -1, len(a))) + +print(m) + +# 446 diff --git a/18/72.py b/18/72.py new file mode 100644 index 0000000..6f3388f --- /dev/null +++ b/18/72.py @@ -0,0 +1,27 @@ +def count(a, i, j): + if i == -1 or j == -1: + return None + + if a[i][j] > 100 and a[i][j] < 500: + return None + + l = count(a, i, j-1) + t = count(a, i-1, j) + + c = a[i][j] if a[i][j] % 3 == 0 or a[i][j] % 4 == 0 else 0 + + 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-11.csv', 'r')] + +print(count(a, len(a)-1, len(a[0])-1)) + +# 1021 222 \ No newline at end of file