-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathturnpike.py
executable file
·71 lines (58 loc) · 1.25 KB
/
turnpike.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
67
68
69
70
71
#!/usr/bin/python
import sys
def main():
l = [2,2,3,3,4,5,6,7,8,10]
PartialDigest(l)
def DeleteMax(l):
m = max(l)
l.remove(m)
return l,m
def PartialDigest(l):
l, width = DeleteMax(l)
x = [0, width]
Place(l, x, width)
def deltas(s):
r = []
for i in s:
for j in s:
if i != j:
r.append(abs(i-j))
return r
def set_included(s, subs):
inc = 1
for i in subs:
present = 0
for j in s:
if i == j:
present = 1
if present == 0:
inc = 0
break
return inc
def remove_set(parent, remset):
for i in remset:
parent.remove(i)
return parent
def Place(l, x, width):
if l == []:
print x
sys.exit(0)
l,y = DeleteMax(l)
xUy = x
xUy.append(y)
difxUy = deltas(xUy)
if set_included(l,xUy):
x = xUy
lmdeltasxUy = remove_set(l,difxUy)
x=Place(lmdeltasxUy, width)
x.remove(y)
wyUx = x
wyUx.append(width - y)
if set_included(l, wyUx):
x.append(width - y)
lmdeltaswyUx = remove_set(l,wyUx)
x = Place(lmdeltaswyUx, width)
x.remove(width - y)
return x
if __name__ == "__main__":
main()