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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
|
#class step:
# def __init__(self, name, unlocks):
# self.name = name;
# self.unlocks = unlocks;
def TransInstr (instruction):
return [instruction[5], instruction[36]];
myinput = {};
currentfilename = "input.txt";
#currentfilename = "testinput.txt";
f = open(currentfilename, 'r');
#list1 = [];
#list2 = {};
list2 = set();
for line in f:
nowinstr = TransInstr(line);
#myinput[nowinstr[1]].append(nowinstr[0]);
list2.add(nowinstr[0]);
#'''
try:
myinput[nowinstr[1]].append(nowinstr[0]);
#myinput[nowinstr[1]] = nowinstr[0];
except:
myinput[nowinstr[1]] = [];
myinput[nowinstr[1]].append(nowinstr[0]);
#'''
print(myinput.keys());
print("##############");
print(list2);
print("##############");
pr1 = list(myinput.keys());
pr1.sort();
pr2 = list(list2);
pr2.sort();
print(pr1);
print(pr2);
print("##############");
print("##############");
print("finding the first step");
CurrentStep = '';
AvailableSteps = [];
#AvailableSteps.append(CurrentStep);
for l in list2:
IsUnique = True;
for k in myinput.keys():
#print("L ", l, "\tK ",k, "\t",l == k);
if (l == k):
IsUnique = False;
break;
if IsUnique:
#CurrentStep = l;
#break;
AvailableSteps.append(l);
print("Unique values are ", AvailableSteps);
print("##############");
print(myinput);
print("##############");
part1 = ""; #CurrentStep;
#list1 = myinput.keys();
#list1.append(CurrentStep);
#print(list1);
while (len(AvailableSteps) != 0):
#input();
AvailableSteps.sort();
CurrentStep = AvailableSteps[0];
part1 += CurrentStep;
print("now ", CurrentStep);
for step in myinput:
#x = myinput[step].index(CurrentStep);
#print(x, "\t",myinput[step]);
#myinput[step].pop(0);
#print(x, "\t",myinput[step]);
try:
#print("try worked");
myinput[step].pop(myinput[step].index(CurrentStep));
except:
#print("skip");
pass;
if (len(myinput[step]) == 0 and part1.find(step) == -1):
AvailableSteps.append(step);
AvailableSteps.pop(0);
print("##################################");
def RemoveDupsOrder(TheString):
a = "";
for letter in TheString:
if not (letter in a):
a += letter;
return a;
print(part1);
part1 = RemoveDupsOrder(part1);
print(part1);
|