-
Notifications
You must be signed in to change notification settings - Fork 0
/
cf784g.py
66 lines (57 loc) · 1.15 KB
/
cf784g.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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
def shift(s,n=1):
ret = ''
ret += '>' * (s-1)
for i in range(10):
ret += '{}[-]{}[<+>-]'.format('<'*n, '>'*n)
ret += '>'
ret += '<'*10
ret += '<' * (s-1)
return ret
exp = input()
nums = []
ops = []
for c in exp:
if c in '0123456789':
nums.append(int(c))
else:
ops.append(c)
lg = len(nums)
ret = ''
for n in nums:
ret += '+' * n
ret += '>'
ret += '\n'
ret += '<'*lg
ret += '\n'
pos = 1
for op in ops:
if op == '-':
ret += '>[-<->]'
elif op == '+':
ret += '>[-<+>]'
pos += 1
ret += '<'*(pos-1)
ret += shift(pos+1)
ret += '>'*(pos-1)
ret += '\n'
ret += '.'
print(ret)
def ope(op, idx1, val1, idx2, val2, ridx):
ret = ''
if op == '+':
ret += '>' * ridx
ret += '+' * (val1+val2)
ret += '<' * ridx
elif op == '-':
ret += '>' * ridx
ret += '-'
def move(sidx, eidx):
if sidx <= eidx:
raise Exception
ret = ''
ret += '>' * (eidx - 1)
ret += '[-]'
ret += '>' * (sidx - eidx)
ret += '[-{}+{}]'.format('<'*(sidx-eidx),'>'*(sidx-eidx))
ret += '<' * (sidx-1)
return ret