From c1fdc53e46d456d6bfa4f5a416a1e58e8a6468ef Mon Sep 17 00:00:00 2001 From: b-idea Date: Thu, 28 Sep 2023 13:25:01 +0200 Subject: added days: 10,11,12,14,16,18 --- 2018/aoc2018-d14.py | 66 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) create mode 100644 2018/aoc2018-d14.py (limited to '2018/aoc2018-d14.py') diff --git a/2018/aoc2018-d14.py b/2018/aoc2018-d14.py new file mode 100644 index 0000000..9e042d0 --- /dev/null +++ b/2018/aoc2018-d14.py @@ -0,0 +1,66 @@ +#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); -- cgit v1.2.3