-
Notifications
You must be signed in to change notification settings - Fork 0
/
79.py
79 lines (72 loc) · 1001 Bytes
/
79.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
72
73
74
75
76
77
78
attempts = """319
680
180
690
129
620
762
689
762
318
368
710
720
710
629
168
160
689
716
731
736
729
316
729
729
710
769
290
719
680
318
389
162
289
162
718
729
319
790
680
890
362
319
760
316
729
380
319
728
716""".split()
def add_wo_doubles(list1, list2):
add = []
for e in list2:
if not e in list1: add.append(e)
return list1 + add
constraints = {}
for a in attempts:
i1,i2,i3 = [c for c in a]
if not constraints.has_key(i1): constraints[i1] = []
constraints[i1]= add_wo_doubles(constraints[i1], [i2,i3])
if not constraints.has_key(i2): constraints[i2] = []
constraints[i2] = add_wo_doubles(constraints[i2], [i3])
constraints = constraints.items()
constraints = sorted(constraints, key=lambda x: len(x[1]))
print constraints
result = []
for i, lc in constraints:
for c in lc:
if c not in result: result = [c] + result
if i in result: print "problem: " + i
else: result = [i] + result
print reduce(lambda x,y: x+y, result)