-
Notifications
You must be signed in to change notification settings - Fork 0
/
LinCooConverter.py
46 lines (39 loc) · 1.18 KB
/
LinCooConverter.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
46
# -*- coding: utf-8 -*-
# LinCoo < (Straight) Line Coordinate
from NumListReader import ReadNumList
# Ext = [ Ext(x), Ext(y), Ext(z), ... ]
# Coo = [ Coo(x), Coo(y), Coo(z), ... ]
def GenerateLinExt(d, Ext):
lExt = [ 1, ]
for i in range(d-1):
p = 1
for j in range(i+1): p *= Ext[j]
lExt.append(p)
return lExt
def ConvertToLinCoo(Ext, Coo : 'must be in Ext'):
d = len(Ext)
lExt = GenerateLinExt(d, Ext)
lCoo = 0
for i in range(d):
lCoo += Coo[i] * lExt[i]
return lCoo
def ConvertFromLinCoo(Ext, lCoo : 'must be in Ext'):
d = len(Ext)
lExt = GenerateLinExt(d, Ext)
Coo = []
for i in range(d): Coo.append(0)
for i in range(d):
Coo[d-i-1] = lCoo // lExt[d-i-1]
lCoo %= lExt[d-i-1]
return Coo
if __name__ == '__main__':
toDo = int(input('To =0 or From =1 : '))
if toDo == 0:
Ext = ReadNumList(input('Ext = '))
Coo = ReadNumList(input('Coo = '))
print(ConvertToLinCoo(Ext, Coo))
else:
Ext = ReadNumList(input('Ext = '))
lCoo = int(input('lCoo = '))
print(ConvertFromLinCoo(Ext, lCoo))
input()