summaryrefslogtreecommitdiff
path: root/2018/aoc2018-d14.py
blob: 9e042d076925c3e6a056e2b54353749c0f648770 (plain)
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
#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);