Solved basic 18th tasks

This commit is contained in:
Dmitriy Shishkov 2021-02-06 23:21:10 +05:00
parent 50e622fac1
commit 06c63d6403
No known key found for this signature in database
GPG Key ID: 7CAE12ED13853CAC
45 changed files with 1707 additions and 8 deletions

7
18/1.cpp Normal file
View File

@ -0,0 +1,7 @@
#include <iostream>
using namespace std;
int main()
{
}

35
18/1.py
View File

@ -1,5 +1,32 @@
n = int(input())
with open('./dat/18-6.txt', 'r') as f:
matrix = [[int(i) for i in e.split()] for e in f.readlines()]
arr = []
with open('./input.txt', 'r') as f:
arr = [f.readline().split() for i in range(n)]
steps = (n - 1) * 2
for row_index, row in enumerate(matrix):
new_row = []
for el_index, el in enumerate(row):
if row_index == 0 and el_index == 0:
new_row.append([matrix[0][0]] * 2)
elif row_index == 0:
new_row.append([new_row[el_index-1][0] + el] * 2)
elif el_index == 0:
new_row.append([arr[row_index-1][el_index][0] + el] * 2)
else:
ns = [max([arr[row_index-1][el_index][0], new_row[el_index-1][0]]) + el,
min([arr[row_index-1][el_index][1], new_row[el_index-1][1]]) + el]
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])

48
18/2.py Normal file
View File

@ -0,0 +1,48 @@
# 1222
def add_10(matrix, x, y, dir):
if (dir):
if (x > 0 and x < len(matrix) - 1):
return 10 if (matrix[x-1][y] % 2 == 0 and matrix[x+1][y] % 2 == 0) or (matrix[x-1][y] % 2 == 1 and matrix[x+1][y] % 2 == 1) else 0
else:
if (y > 0 and y < len(matrix[x]) - 1):
return 10 if (matrix[x][y-1] % 2 == 0 and matrix[x][y+1] % 2 == 0) or (matrix[x][y-1] % 2 == 1 and matrix[x][y+1] % 2 == 1) else 0
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 = []
for row_index, row in enumerate(matrix):
new_row = []
for el_index, el in enumerate(row):
if row_index == 0 and el_index == 0:
new_row.append(el)
elif row_index == 0:
new_row.append(new_row[el_index-1] + el)
elif el_index == 0:
new_row.append(arr[row_index-1][el_index] + el)
else:
ns = min(arr[row_index-1][el_index] + add_10(matrix, row_index, el_index, 0),
new_row[el_index-1] + add_10(matrix, row_index, el_index, 1)) + el
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])

18
18/3.py Normal file
View File

@ -0,0 +1,18 @@
# 345
with open('./dat/18-17.txt', 'r') as f:
p = float('+inf')
s = 0
ms = float('-inf')
for sn in f.readlines():
n = float(sn)
if n < p:
s += n
else:
if s > ms:
ms = s
s = 0
p = n
print(int(ms))

18
18/4.py Normal file
View File

@ -0,0 +1,18 @@
# 29
with open('./dat/18-77.txt', 'r') as f:
p = float(f.readline())
ms = float('-inf')
s = 0
for sn in f.readlines():
n = float(sn)
if abs(n - p) >= 20:
s += n
if s > ms:
ms = s
else:
s = 0
p = n
print(int(ms))

10
18/dat/18-0.csv Normal file
View File

@ -0,0 +1,10 @@
51;21;93;48;45;100;67;39;18;29
57;43;97;51;92;10;93;32;19;58
63;16;31;16;78;88;90;72;37;67
10;57;64;25;96;50;81;65;91;69
99;43;95;7;40;76;18;34;5;65
35;19;71;77;64;38;62;56;10;2
100;57;27;26;51;33;100;11;53;1
11;79;49;46;37;69;80;31;25;39
22;71;20;23;11;12;39;16;64;34
4;25;87;84;30;48;77;13;40;33
1 51 21 93 48 45 100 67 39 18 29
2 57 43 97 51 92 10 93 32 19 58
3 63 16 31 16 78 88 90 72 37 67
4 10 57 64 25 96 50 81 65 91 69
5 99 43 95 7 40 76 18 34 5 65
6 35 19 71 77 64 38 62 56 10 2
7 100 57 27 26 51 33 100 11 53 1
8 11 79 49 46 37 69 80 31 25 39
9 22 71 20 23 11 12 39 16 64 34
10 4 25 87 84 30 48 77 13 40 33

BIN
18/dat/18-0.xls Normal file

Binary file not shown.

BIN
18/dat/18-0_ready.xls Normal file

Binary file not shown.

BIN
18/dat/18-1.xls Normal file

Binary file not shown.

BIN
18/dat/18-10.xls Normal file

Binary file not shown.

BIN
18/dat/18-11.xls Normal file

Binary file not shown.

BIN
18/dat/18-12.xls Normal file

Binary file not shown.

BIN
18/dat/18-13.xls Normal file

Binary file not shown.

BIN
18/dat/18-14.xls Normal file

Binary file not shown.

BIN
18/dat/18-14_ready.xls Normal file

Binary file not shown.

BIN
18/dat/18-15.xls Normal file

Binary file not shown.

BIN
18/dat/18-16.xls Normal file

Binary file not shown.

500
18/dat/18-17.txt Normal file
View File

@ -0,0 +1,500 @@
115.36
148.05
31.52
89.34
82.87
80.23
78.93
48.47
58.82
127.06
135.97
119.56
79.60
29.54
5.99
64.98
58.78
96.20
94.01
77.80
69.62
89.07
25.34
107.61
32.93
125.99
35.51
67.87
69.19
55.12
105.86
13.48
102.54
123.56
6.56
47.62
88.94
114.01
8.00
80.69
34.98
30.94
25.29
28.62
113.82
63.27
15.61
136.60
58.25
53.12
23.19
30.90
145.18
81.75
151.15
66.57
58.56
154.02
140.03
127.79
49.65
121.52
38.29
50.85
143.47
102.29
72.33
60.84
135.72
46.02
18.27
109.58
25.62
127.34
150.58
94.61
95.81
96.38
128.20
98.20
45.46
103.89
127.28
41.17
138.81
138.61
47.27
90.26
25.11
130.68
6.52
48.07
148.54
78.48
140.00
84.10
142.01
15.51
153.46
43.11
27.92
106.22
15.60
73.66
14.36
120.63
106.63
105.02
18.98
58.37
131.99
85.21
149.70
56.72
106.51
77.89
63.30
48.33
15.17
115.31
82.66
40.23
34.84
106.86
87.29
93.06
69.62
56.43
126.72
23.29
98.25
140.52
23.50
124.84
65.35
49.44
127.84
77.31
24.24
80.02
87.87
130.38
14.06
128.47
13.29
85.01
50.93
110.43
132.11
125.54
59.61
143.77
153.72
11.28
67.69
134.24
62.11
105.40
22.22
67.39
31.97
67.56
34.99
129.33
18.99
34.74
42.05
39.45
97.43
142.81
36.65
132.58
150.27
136.38
89.99
68.84
50.40
151.70
24.96
36.39
46.03
86.83
109.28
25.87
37.40
75.32
120.68
37.52
18.27
29.30
14.98
50.64
92.97
32.18
86.17
11.47
71.05
36.24
23.58
137.88
107.92
74.15
102.64
141.46
83.27
113.76
68.82
64.62
33.24
17.56
144.80
147.66
84.49
68.44
104.01
118.57
12.92
72.10
28.21
20.65
115.63
74.97
35.58
38.69
96.35
120.58
142.47
107.44
76.24
51.21
65.78
122.83
33.37
26.47
141.93
90.27
50.07
107.14
11.72
135.57
117.58
51.47
143.38
35.12
104.89
129.72
27.09
96.83
119.05
133.76
63.12
81.12
58.09
98.84
128.04
68.75
114.48
128.97
74.38
73.82
139.97
124.96
108.58
130.81
34.17
44.21
92.15
131.73
131.36
32.43
33.81
29.38
102.26
144.72
27.98
74.91
123.22
63.76
115.09
66.36
6.72
107.08
85.35
153.24
68.90
53.81
16.45
98.71
20.71
42.78
44.11
93.06
49.67
69.84
37.35
81.73
138.80
125.48
86.42
134.51
67.39
31.78
84.07
92.68
126.87
134.14
38.53
16.66
42.48
154.79
57.85
104.25
38.68
11.24
127.89
141.84
69.14
33.09
49.21
115.06
100.59
68.55
113.68
14.87
113.40
78.64
73.37
10.43
86.49
79.70
79.88
147.51
80.13
145.64
101.60
76.77
29.88
108.91
12.09
17.33
98.17
130.08
49.51
25.54
39.12
43.48
42.50
137.74
147.41
120.96
87.30
17.34
122.04
116.39
144.95
136.22
55.94
35.79
45.90
139.65
58.06
96.71
54.91
46.59
152.27
80.43
11.67
18.03
18.87
97.33
25.41
86.44
123.41
62.75
9.38
152.74
66.90
31.18
44.86
25.68
32.74
43.97
97.73
19.46
75.66
102.28
129.80
123.31
137.07
102.30
144.24
18.46
85.89
52.01
69.22
130.63
99.13
21.15
59.78
92.15
96.70
27.66
10.33
16.78
60.00
92.20
17.02
27.59
76.19
151.15
35.75
59.67
22.12
90.55
109.88
103.40
82.15
154.08
108.71
85.00
18.41
136.41
138.80
49.72
85.22
150.06
6.31
64.53
151.24
76.84
52.59
66.56
137.03
57.10
23.67
99.98
73.92
12.75
108.88
131.91
129.25
123.27
43.91
147.67
121.68
94.61
144.50
132.51
35.31
129.18
96.56
108.95
77.65
60.45
134.12
35.72
46.58
51.75
31.53
59.90
51.08
55.17
86.43
28.78
65.99
41.26
13.33
42.57
82.87
110.51
75.96
135.75
119.78
48.26
57.95
78.69
131.61
64.69
146.99
40.72
25.85
44.50
30.41
49.81
91.05
143.51
23.28
23.16
21.92
143.62
103.87
31.95
106.78
19.01
126.41
151.22
66.51
59.34
51.82
82.90

BIN
18/dat/18-17.xls Normal file

Binary file not shown.

BIN
18/dat/18-18.xls Normal file

Binary file not shown.

BIN
18/dat/18-2.xls Normal file

Binary file not shown.

BIN
18/dat/18-3.xls Normal file

Binary file not shown.

BIN
18/dat/18-4.xls Normal file

Binary file not shown.

BIN
18/dat/18-5.xls Normal file

Binary file not shown.

10
18/dat/18-6.txt Normal file
View File

@ -0,0 +1,10 @@
48 65 28 73 28 74 61 58 59 49
32 94 37 57 65 75 15 5 56 6
17 90 74 85 84 66 12 42 99 30
55 66 41 23 93 3 73 26 70 19
84 87 74 90 68 48 40 97 10 43
37 67 26 24 83 49 11 39 29 51
3 31 99 92 81 3 49 51 32 55
22 35 6 6 68 46 17 34 37 89
41 63 58 32 17 32 59 82 91 33
7 61 53 90 42 49 83 95 96 74

BIN
18/dat/18-6.xls Normal file

Binary file not shown.

BIN
18/dat/18-7.xls Normal file

Binary file not shown.

1000
18/dat/18-77.txt Normal file

File diff suppressed because it is too large Load Diff

BIN
18/dat/18-77.xls Normal file

Binary file not shown.

BIN
18/dat/18-8.xls Normal file

Binary file not shown.

BIN
18/dat/18-9.xls Normal file

Binary file not shown.

10
18/dat/18-J1.csv Normal file
View File

@ -0,0 +1,10 @@
65;61;87;81;49;41;64;29;60;49
47;13;81;41;20;97;32;84;67;13
77;14;96;86;92;33;78;47;29;59
50;78;68;12;87;69;98;98;36;89
18;42;75;30;45;95;42;82;52;85
96;16;25;93;95;94;52;88;57;56
99;29;60;10;16;26;25;85;16;28
54;97;77;58;75;60;31;44;39;76
87;73;79;18;47;74;12;74;33;93
77;89;38;95;98;19;84;59;65;98
1 65 61 87 81 49 41 64 29 60 49
2 47 13 81 41 20 97 32 84 67 13
3 77 14 96 86 92 33 78 47 29 59
4 50 78 68 12 87 69 98 98 36 89
5 18 42 75 30 45 95 42 82 52 85
6 96 16 25 93 95 94 52 88 57 56
7 99 29 60 10 16 26 25 85 16 28
8 54 97 77 58 75 60 31 44 39 76
9 87 73 79 18 47 74 12 74 33 93
10 77 89 38 95 98 19 84 59 65 98

BIN
18/dat/18-J1.xls Normal file

Binary file not shown.

11
18/dat/18-J2.csv Normal file
View File

@ -0,0 +1,11 @@
17;26;17;31;33;3;17;14;2;3;33
8;30;40;38;33;19;48;4;30;34;49
31;25;35;27;7;46;27;9;15;7;17
45;24;2;35;31;23;27;1;19;48;6
3;3;26;23;43;8;12;15;47;2;27
3;33;27;44;11;6;40;41;18;32;50
40;31;48;46;8;1;17;25;40;31;6
27;3;13;21;4;29;22;39;42;18;33
25;24;3;49;15;41;32;10;8;31;16
20;20;39;40;49;43;3;12;33;6;16
47;3;18;37;30;8;33;43;42;19;45
1 17 26 17 31 33 3 17 14 2 3 33
2 8 30 40 38 33 19 48 4 30 34 49
3 31 25 35 27 7 46 27 9 15 7 17
4 45 24 2 35 31 23 27 1 19 48 6
5 3 3 26 23 43 8 12 15 47 2 27
6 3 33 27 44 11 6 40 41 18 32 50
7 40 31 48 46 8 1 17 25 40 31 6
8 27 3 13 21 4 29 22 39 42 18 33
9 25 24 3 49 15 41 32 10 8 31 16
10 20 20 39 40 49 43 3 12 33 6 16
11 47 3 18 37 30 8 33 43 42 19 45

BIN
18/dat/18-J2.xls Normal file

Binary file not shown.

14
18/dat/18-J3.csv Normal file
View File

@ -0,0 +1,14 @@
38;36;50;68;33;68;61;49;19;35;96;26;75;20
33;88;25;13;60;40;25;50;51;73;75;63;52;52
24;79;94;69;25;67;22;77;1;15;22;2;47;40
99;32;57;68;48;79;95;22;45;72;17;13;25;97
70;32;39;13;21;84;95;28;60;38;87;30;92;3
41;26;68;93;4;81;78;24;77;48;29;47;19;54
77;16;63;29;34;31;36;3;20;34;71;41;11;20
74;19;81;58;47;63;93;25;39;45;31;8;19;42
69;37;91;57;38;85;24;85;34;45;27;15;12;97
67;53;72;69;74;54;7;23;56;38;41;4;83;33
73;65;40;17;69;14;73;30;34;43;46;25;43;85
57;30;88;65;34;93;50;88;100;81;99;91;43;50
56;30;14;70;93;14;66;75;95;74;45;82;89;81
18;51;72;78;91;25;96;83;72;16;71;86;62;65
1 38 36 50 68 33 68 61 49 19 35 96 26 75 20
2 33 88 25 13 60 40 25 50 51 73 75 63 52 52
3 24 79 94 69 25 67 22 77 1 15 22 2 47 40
4 99 32 57 68 48 79 95 22 45 72 17 13 25 97
5 70 32 39 13 21 84 95 28 60 38 87 30 92 3
6 41 26 68 93 4 81 78 24 77 48 29 47 19 54
7 77 16 63 29 34 31 36 3 20 34 71 41 11 20
8 74 19 81 58 47 63 93 25 39 45 31 8 19 42
9 69 37 91 57 38 85 24 85 34 45 27 15 12 97
10 67 53 72 69 74 54 7 23 56 38 41 4 83 33
11 73 65 40 17 69 14 73 30 34 43 46 25 43 85
12 57 30 88 65 34 93 50 88 100 81 99 91 43 50
13 56 30 14 70 93 14 66 75 95 74 45 82 89 81
14 18 51 72 78 91 25 96 83 72 16 71 86 62 65

BIN
18/dat/18-J3.xls Normal file

Binary file not shown.

15
18/dat/18-J4.csv Normal file
View File

@ -0,0 +1,15 @@
23;69;20;60;18;61;18;0;24;80;34;46;47;77;84
78;97;45;72;72;68;78;27;88;40;70;72;21;82;12
55;19;0;88;77;29;35;42;87;83;0;0;18;56;65
84;83;0;68;71;58;73;16;88;40;28;72;35;47;58
62;84;23;37;81;36;46;86;94;16;38;37;98;99;35
77;92;62;64;47;0;51;27;71;26;20;40;24;60;25
16;19;84;63;93;0;87;91;0;11;47;32;30;92;84
70;29;41;48;58;44;92;94;22;72;95;95;72;35;34
26;51;16;10;24;43;15;89;0;12;29;57;44;98;76
69;94;37;24;36;0;0;0;10;90;74;24;13;39;89
0;90;87;93;10;51;14;49;64;86;0;30;12;57;75
61;90;81;61;37;84;63;35;16;94;0;77;53;83;18
22;16;0;91;17;52;15;31;65;61;85;53;63;88;91
61;73;0;94;55;84;43;91;47;74;21;55;10;27;77
77;79;91;53;27;94;82;19;38;57;42;31;19;45;31
1 23 69 20 60 18 61 18 0 24 80 34 46 47 77 84
2 78 97 45 72 72 68 78 27 88 40 70 72 21 82 12
3 55 19 0 88 77 29 35 42 87 83 0 0 18 56 65
4 84 83 0 68 71 58 73 16 88 40 28 72 35 47 58
5 62 84 23 37 81 36 46 86 94 16 38 37 98 99 35
6 77 92 62 64 47 0 51 27 71 26 20 40 24 60 25
7 16 19 84 63 93 0 87 91 0 11 47 32 30 92 84
8 70 29 41 48 58 44 92 94 22 72 95 95 72 35 34
9 26 51 16 10 24 43 15 89 0 12 29 57 44 98 76
10 69 94 37 24 36 0 0 0 10 90 74 24 13 39 89
11 0 90 87 93 10 51 14 49 64 86 0 30 12 57 75
12 61 90 81 61 37 84 63 35 16 94 0 77 53 83 18
13 22 16 0 91 17 52 15 31 65 61 85 53 63 88 91
14 61 73 0 94 55 84 43 91 47 74 21 55 10 27 77
15 77 79 91 53 27 94 82 19 38 57 42 31 19 45 31

BIN
18/dat/18-J4.xls Normal file

Binary file not shown.

15
18/dat/18-J5.csv Normal file
View File

@ -0,0 +1,15 @@
49;56;35;57;52;93;91;95;66;80;31;97;98;22;92
80;33;76;37;58;46;79;85;96;60;57;53;51;61;84
84;70;51;62;57;78;76;25;28;64;33;59;28;99;78
83;32;73;94;32;26;92;39;92;45;73;85;28;51;26
87;75;61;83;26;48;15;59;34;37;18;66;90;26;12
77;79;84;48;16;79;47;36;75;57;24;41;98;62;42
52;49;71;66;58;95;86;27;67;73;38;46;39;59;74
55;29;72;32;44;56;33;42;83;53;11;36;100;90;27
39;28;71;59;100;83;68;59;80;79;39;73;91;75;13
46;76;10;30;10;51;76;85;28;10;12;35;100;94;77
41;63;30;99;88;13;70;67;71;66;22;62;73;49;81
43;90;67;95;46;30;71;47;64;76;95;70;59;31;58
22;54;72;87;15;48;92;44;79;66;73;41;42;19;62
50;16;13;82;83;12;37;99;82;98;93;19;46;62;56
51;81;99;67;78;45;82;73;73;83;93;94;53;19;68
1 49 56 35 57 52 93 91 95 66 80 31 97 98 22 92
2 80 33 76 37 58 46 79 85 96 60 57 53 51 61 84
3 84 70 51 62 57 78 76 25 28 64 33 59 28 99 78
4 83 32 73 94 32 26 92 39 92 45 73 85 28 51 26
5 87 75 61 83 26 48 15 59 34 37 18 66 90 26 12
6 77 79 84 48 16 79 47 36 75 57 24 41 98 62 42
7 52 49 71 66 58 95 86 27 67 73 38 46 39 59 74
8 55 29 72 32 44 56 33 42 83 53 11 36 100 90 27
9 39 28 71 59 100 83 68 59 80 79 39 73 91 75 13
10 46 76 10 30 10 51 76 85 28 10 12 35 100 94 77
11 41 63 30 99 88 13 70 67 71 66 22 62 73 49 81
12 43 90 67 95 46 30 71 47 64 76 95 70 59 31 58
13 22 54 72 87 15 48 92 44 79 66 73 41 42 19 62
14 50 16 13 82 83 12 37 99 82 98 93 19 46 62 56
15 51 81 99 67 78 45 82 73 73 83 93 94 53 19 68

BIN
18/dat/18-J5.xls Normal file

Binary file not shown.

BIN
18/dat/18-k1.xls Normal file

Binary file not shown.

BIN
18/dat/18-k2.xls Normal file

Binary file not shown.

BIN
18/dat/18-k3.xls Normal file

Binary file not shown.

View File

@ -1,4 +0,0 @@
1 8 8 4
10 1 1 3
1 3 12 2
2 3 5 6