Skip to content

Commit 7a7b7f9

Browse files
committed
[main] hello
1 parent e58d73a commit 7a7b7f9

File tree

18 files changed

+375
-0
lines changed

18 files changed

+375
-0
lines changed
Binary file not shown.
Binary file not shown.
0 Bytes
Binary file not shown.
Binary file not shown.
Binary file not shown.
0 Bytes
Binary file not shown.

pythonProblems/dp/dbl_linear.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
from typing import List
2+
3+
4+
def dbl_linear(n: int) -> List[int]:
5+
"""
6+
7+
Args:
8+
n (_type_): _description_
9+
"""
10+
seq = [1]
11+
ind = 0
12+
gen_numbers = 1
13+
y_array = []
14+
z_array = []
15+
while len(seq) < n:
16+
for eachnum in seq[ind: ind + gen_numbers]:
17+
y_array.append(2 * eachnum + 1)
18+
for eachnum in seq[ind: ind + gen_numbers]:
19+
z_array.append(3 * eachnum + 1)
20+
ind += gen_numbers
21+
gen_numbers = ind + (gen_numbers * 2) - ind
22+
seq.extend(y_array)
23+
seq.extend(z_array)
24+
y_array = []
25+
z_array = []
26+
return seq[u]
27+
# u = [1, 3, 4, 7, 9, 10, 13, 15, 19, 21, 22, 27, ...]
28+
29+
30+
if __name__ == '__main__':
31+
u = 10
32+
dbl_linear(u)

pythonProblems/dp/diffutil.py

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
2+
from pprint import pprint
3+
4+
5+
def diff_utility(str1: str, str2: str) -> None:
6+
table = []
7+
for _ in str1:
8+
table_row = []
9+
for __ in str2:
10+
table_row.append(0)
11+
table.append(table_row)
12+
table_row = []
13+
14+
for i in range(len(str1)):
15+
for j in range(len(str2)):
16+
if str1[i] == str2[j]:
17+
table[i][j] = 0
18+
else:
19+
top_value, left_value, right_value, bottom_value = float(
20+
'inf'), float('inf'), float('inf'), float('inf')
21+
if i > 0:
22+
top_value = table[i - 1][j]
23+
if j > 0:
24+
left_value = table[i][j - 1]
25+
if j < len(table[i]) - 1:
26+
right_value = table[i][j + 1]
27+
if i < len(table) - 1:
28+
bottom_value = table[i + 1][j]
29+
table[i][j] = min(top_value, left_value,
30+
right_value, bottom_value) + 1
31+
pprint(table)
32+
33+
34+
if __name__ == '__main__':
35+
x = 'XMJYAUZ'
36+
y = 'XMJAATZ'
37+
diff_utility(x, y)

pythonProblems/dp/ilyaqueries.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
2+
3+
if __name__ == '__main__':
4+
query_string = input()
5+
num_queries = int(input())
6+
for eachquery in range(num_queries):
7+
s_f = input().split(" ")
8+
start = int(s_f[0])
9+
finish = int(s_f[1])
10+
count = 0
11+
for i in range(start - 1, finish - 1):
12+
if query_string[i] == query_string[i + 1]:
13+
count += 1
14+
print(count)

pythonProblems/dp/isValidSudoku.py

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
from typing import List
2+
3+
4+
class Solution:
5+
def isValidSudoku(self, board: List[List[str]]) -> bool:
6+
for eachrow in board:
7+
row_values = []
8+
for eachvalue in eachrow:
9+
if eachvalue != '.' and eachvalue.isnumeric():
10+
row_values.append(int(eachvalue))
11+
if len(set(row_values)) != len(row_values):
12+
print('row')
13+
return False
14+
for i in range(len(board)):
15+
column_values = []
16+
for j in range(len(board[i])):
17+
if board[j][i] != '.' and board[j][i].isnumeric():
18+
column_values.append(int(board[j][i]))
19+
if len(set(column_values)) != len(column_values):
20+
print('col')
21+
return False
22+
for i in range(0, len(board) - 2, 3):
23+
grid_values = []
24+
# controls row traversal
25+
for j in range(0, len(board[i]) - 2, 3):
26+
grid_values = []
27+
for k in range(j, j + 3):
28+
# controls inner row traversal
29+
if board[i][k] != '.':
30+
grid_values.append(int(board[i][k]))
31+
if board[i + 1][k] != '.':
32+
grid_values.append(int(board[i + 1][k]))
33+
if board[i + 2][k] != '.':
34+
grid_values.append(int(board[i + 2][k]))
35+
if len(set(grid_values)) != len(grid_values):
36+
print('grid', grid_values)
37+
return False
38+
return True
39+
40+
41+
if __name__ == '__main__':
42+
board = [
43+
[".", ".", ".", ".", ".", ".", "5", ".", "."],
44+
[".", ".", ".", ".", ".", ".", ".", ".", "."],
45+
[".", ".", ".", ".", ".", ".", ".", ".", "."],
46+
["9", "3", ".", ".", "2", ".", "4", ".", "."],
47+
[".", ".", "7", ".", ".", ".", "3", ".", "."],
48+
[".", ".", ".", ".", ".", ".", ".", ".", "."],
49+
[".", ".", ".", "3", "4", ".", ".", ".", "."],
50+
[".", ".", ".", ".", ".", "3", ".", ".", "."],
51+
[".", ".", ".", ".", ".", "5", "2", ".", "."]]
52+
sol = Solution()
53+
print(sol.isValidSudoku(board))

0 commit comments

Comments
 (0)