#advent of code 2018 #day 14 #part 1 & part 2 #there should be a faster way to compute the results #no idea how to do it at the moment import time f = open("input.txt",'r'); myinput = int(f.readline()); Testing = False; #Testing = True; if Testing: f.close(); #f = open("testinput.txt",'r'); myinput = 9; myinput = 5; myinput = 18; myinput = 2018; recipes = [3,7]; elf1 = 0; elf2 = 1; StillSearching = True; part2 = ""; ElapsedTime = 0; starttime = time.time(); while (StillSearching): newrecipes = recipes[elf1] + recipes[elf2]; newrecipes = str(newrecipes); for r in newrecipes: recipes.append(int(r)); move1 = 1 + recipes[elf1]; move2 = 1 + recipes[elf2]; elf1 = (move1 + elf1)%len(recipes); elf2 = (move2 + elf2)%len(recipes); recipesstring = ""; for n in range(-len(str(myinput))-1,0): recipesstring += str( recipes[n%len(recipes)] ); if (recipesstring[:-1] == str(myinput)): part2 = len(recipes) - len(str(myinput)) -1; print("p2 ", part2); elif (recipesstring[1:] == str(myinput)): part2 = len(recipes) - len(str(myinput)); print("p2 ", part2); if (len(recipes)>=myinput+10): if (part2 != ""): StillSearching = False; part1 = ""; for i in range(myinput,myinput+10): part1 += str(recipes[i]); endtime = time.time() - starttime; print("FIN -- ", endtime, "sec"); print("part 1: ", part1); print("part 2: ", part2);