Skip to content

Commit 0bc1f0d

Browse files
committed
[main] Added in math practice
1 parent 3b9d908 commit 0bc1f0d

File tree

2 files changed

+242
-0
lines changed

2 files changed

+242
-0
lines changed

pythonProblems/base75/base75.py

Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
BASE_75 = [
2+
"A",
3+
"B",
4+
"C",
5+
"D",
6+
"E",
7+
"F",
8+
"G",
9+
"H",
10+
"I",
11+
"J",
12+
"K",
13+
"L",
14+
"M",
15+
"N",
16+
"O",
17+
"P",
18+
"Q",
19+
"R",
20+
"S",
21+
"T",
22+
"U",
23+
"V",
24+
"W",
25+
"X",
26+
"Y",
27+
"Z",
28+
"a",
29+
"b",
30+
"c",
31+
"d",
32+
"e",
33+
"f",
34+
"g",
35+
"h",
36+
"i",
37+
"j",
38+
"k",
39+
"l",
40+
"m",
41+
"n",
42+
"o",
43+
"p",
44+
"q",
45+
"r",
46+
"s",
47+
"t",
48+
"u",
49+
"v",
50+
"w",
51+
"x",
52+
"y",
53+
"z",
54+
"0",
55+
"1",
56+
"2",
57+
"3",
58+
"4",
59+
"5",
60+
"6",
61+
"7",
62+
"8",
63+
"9",
64+
"!",
65+
"#",
66+
"$",
67+
"%",
68+
"&",
69+
"(",
70+
")",
71+
"*",
72+
"+",
73+
",",
74+
".",
75+
"/",
76+
":",
77+
]
78+
79+
80+
def b75encode(orig: bytes) -> bytes:
81+
chunks = []
82+
sub_chunk = []
83+
appended_bytes = 0
84+
for each_byte in orig:
85+
sub_chunk.append(each_byte)
86+
if len(sub_chunk) == 7:
87+
chunks.append(sub_chunk)
88+
sub_chunk = []
89+
if len(sub_chunk) > 0:
90+
appended_bytes = 7 - len(sub_chunk)
91+
while len(sub_chunk) < 7:
92+
sub_chunk.append(0)
93+
chunks.append(sub_chunk)
94+
sub_chunk = []
95+
96+
for ind, element in enumerate(chunks):
97+
# Convert chunk to massive binary number
98+
cloned_arr = element[:]
99+
for cloned_ind, cloned_element in enumerate(cloned_arr):
100+
print(type(cloned_element))
101+
cloned_arr[cloned_ind] = cloned_element % 75
102+
chunks[ind] = cloned_arr[:]
103+
104+
print(chunks)
105+
106+
107+
def b75decode(orig: bytes) -> bytes:
108+
print(orig)
109+
110+
111+
if __name__ == "__main__":
112+
original = b"Simple text."
113+
encoded = b"Xh&1*IqZjg2gKO:a&E2"
114+
b75encode(original)
115+
b75decode(encoded)
Lines changed: 127 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,127 @@
1+
import numpy as np
2+
3+
mat1 = [[1, 1], [2, 2]]
4+
mat2 = [[1, 1], [1, 2]]
5+
6+
first_frac = mat1[0][0] / mat1[1][0]
7+
second_frac = mat1[0][1] / mat1[1][1]
8+
9+
print(first_frac, second_frac)
10+
11+
twofirst = mat2[0][0] / mat2[1][0]
12+
twosecond = mat2[0][1] / mat2[1][1]
13+
14+
print(twofirst, twosecond)
15+
16+
ff1 = mat1[0][0] * mat1[1][1]
17+
ff2 = mat1[0][1] * mat1[1][0]
18+
19+
print(ff1, ff2, ff1 - ff2)
20+
21+
ff11 = mat2[0][0] * mat2[1][1]
22+
ff22 = mat2[1][0] * mat2[0][1]
23+
24+
print(ff11, ff22, ff11 - ff22)
25+
26+
27+
mat3 = [[5, 1], [-1, 3]]
28+
29+
30+
first3 = mat3[0][0] * mat3[1][1]
31+
second3 = mat3[0][1] * mat3[1][0]
32+
33+
print(first3, second3, first3 - second3) ## singular
34+
35+
mat4 = [[2, -1], [-6, 3]]
36+
37+
first4 = mat4[0][0] * mat4[1][1]
38+
second4 = mat4[0][1] * mat4[1][0]
39+
40+
print(first4, second4, first4 - second4)
41+
42+
mat5 = [[2, 3], [2, 4]]
43+
44+
first5 = mat5[0][0] * mat5[1][1]
45+
second5 = mat5[0][1] * mat5[1][0]
46+
47+
print(first5, second5, first5 - second5)
48+
49+
mat1 = [[1, 0, 1], [0, 1, 0], [3, 3, 3]]
50+
51+
dt_1_first_diag = mat1[0][0] * mat1[1][1] * mat1[2][2]
52+
dt_1_second_diag = mat1[0][1] * mat1[1][2] * mat1[2][0]
53+
dt_1_third_diag = mat1[0][2] * mat1[1][0] * mat1[2][1]
54+
55+
dt_1_anti_first_diag = mat1[0][2] * mat1[1][1] * mat1[2][0]
56+
dt_1_anti_second_diag = mat1[0][1] * mat1[1][0] * mat1[2][2]
57+
dt_1_anti_third_diag = mat1[0][0] * mat1[1][2] * mat1[2][1]
58+
59+
dt_1 = (dt_1_first_diag + dt_1_second_diag + dt_1_third_diag) - (
60+
dt_1_anti_first_diag - dt_1_anti_second_diag - dt_1_anti_third_diag
61+
)
62+
63+
print(dt_1)
64+
65+
66+
mat2 = [[1, 1, 1], [1, 1, 2], [0, 0, -1]]
67+
68+
69+
dt_2_first_diag = mat2[0][0] * mat2[1][1] * mat2[2][2]
70+
dt_2_second_diag = mat2[0][1] * mat2[1][2] * mat2[2][0]
71+
dt_2_third_diag = mat2[0][2] * mat2[1][0] * mat2[2][1]
72+
73+
dt_2_anti_first_diag = mat2[0][2] * mat2[1][1] * mat2[2][0]
74+
dt_2_anti_second_diag = mat2[0][1] * mat2[1][0] * mat2[2][2]
75+
dt_2_anti_third_diag = mat2[0][0] * mat2[1][2] * mat2[2][1]
76+
77+
dt_2 = (dt_2_first_diag + dt_2_second_diag + dt_2_third_diag) + (
78+
dt_2_anti_first_diag - dt_2_anti_second_diag - dt_2_anti_third_diag
79+
)
80+
81+
print(dt_2)
82+
83+
84+
mat3 = [[1, 1, 1], [0, 2, 2], [0, 0, 3]]
85+
86+
dt_3_first_diag = mat3[0][0] * mat3[1][1] * mat3[2][2]
87+
dt_3_second_diag = mat3[0][1] * mat3[1][2] * mat3[2][0]
88+
dt_3_third_diag = mat3[0][2] * mat3[1][0] * mat3[2][1]
89+
90+
dt_3_anti_first_diag = mat3[0][2] * mat3[1][1] * mat3[2][0]
91+
dt_3_anti_second_diag = mat3[0][1] * mat3[1][0] * mat3[2][2]
92+
dt_3_anti_third_diag = mat3[0][0] * mat3[1][2] * mat3[2][1]
93+
94+
dt_3_first = dt_3_first_diag + dt_3_second_diag + dt_3_third_diag
95+
dt_3_second = dt_3_anti_first_diag - dt_3_anti_second_diag - dt_3_anti_third_diag
96+
97+
dt_3 = dt_3_first + dt_3_second
98+
99+
print(dt_3)
100+
101+
mat4 = [[1, 2, 5], [0, 3, -2], [2, 4, 10]]
102+
103+
dt_4_first_diag = mat4[0][0] * mat4[1][1] * mat4[2][2]
104+
dt_4_second_diag = mat4[0][1] * mat4[1][2] * mat4[2][0]
105+
dt_4_third_diag = mat4[0][2] * mat4[1][0] * mat4[2][1]
106+
107+
dt_4_anti_first_diag = mat4[0][2] * mat4[1][1] * mat4[2][0]
108+
dt_4_anti_second_diag = mat4[0][1] * mat4[1][0] * mat4[2][2]
109+
dt_4_anti_third_diag = mat4[0][0] * mat4[1][2] * mat4[2][1]
110+
111+
print(
112+
"first = {} {} {} second = {} {} {}".format(
113+
dt_4_first_diag,
114+
dt_4_second_diag,
115+
dt_4_third_diag,
116+
dt_4_anti_first_diag,
117+
dt_4_anti_second_diag,
118+
dt_4_anti_third_diag,
119+
)
120+
)
121+
122+
dt_4_first = dt_4_first_diag + dt_4_second_diag + dt_4_third_diag
123+
dt_4_second = dt_4_anti_first_diag + dt_4_anti_second_diag + dt_4_anti_third_diag
124+
125+
dt_4 = dt_4_first - dt_4_second
126+
127+
print("dt4 = {}".format(dt_4))

0 commit comments

Comments
 (0)