From 3d1bbf7d8f051a8b8c8473cac699a91f8e87dfda Mon Sep 17 00:00:00 2001 From: b-idea Date: Sat, 15 Jul 2023 22:40:33 +0200 Subject: code update again --- 2018/aoc2018-d07-1.py | 116 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 116 insertions(+) create mode 100755 2018/aoc2018-d07-1.py (limited to '2018/aoc2018-d07-1.py') diff --git a/2018/aoc2018-d07-1.py b/2018/aoc2018-d07-1.py new file mode 100755 index 0000000..b734e18 --- /dev/null +++ b/2018/aoc2018-d07-1.py @@ -0,0 +1,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); -- cgit v1.2.3