-
Notifications
You must be signed in to change notification settings - Fork 0
/
gen.py
45 lines (36 loc) · 972 Bytes
/
gen.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import sys
s = r"\["
e = r"\]" + "\n"
beg = r"\begin{bmatrix}"
end = r"\end{bmatrix}"
def eucs(a, b):
if b > a:
a, b = b, a
print(s)
matrix = [[1,0,a], [0,1,b]]
euc(matrix, False)
print(e)
def output(m):
print(beg)
for l in m:
print(' & '.join([str(x) for x in l]) + r" \\")
print(end)
print('=')
def euc(matrix, alt):
output(matrix)
if matrix[0][2] == 0 or matrix[1][2] == 0:
return
mult = matrix[alt][2] // matrix[not alt][2]
# Subtract the smaller row from the bigger row without using SciPy matrices
for x in range(3):
matrix[alt][x] = matrix[alt][x] - matrix[not alt][x] * mult
euc(matrix, not alt)
if __name__ == '__main__':
for arg in sys.argv[1:]:
try:
a, b = arg.split(',')
a, b = int(a), int(b)
except:
print("Argument parsing failed for arg '{}'".format(arg))
continue
eucs(a, b)