blob: 9922c398c1cc1ee4582d1e5c99a7b08bcce596aa (
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
67
68
|
#advent of code 2018
#day 12
#part 1 & part 2
generationnumber1 = 20; #part1
generationnumber2 = 10000; #steady state
generationnumber3 = 50000000000; #part2
f = open("input.txt", 'r');
testing = False;
#testing = True;
if testing:
f.close();
f = open("testinput.txt", 'r');
PlantInitialState = f.readline();
PlantInitialState = PlantInitialState.replace("initial state: ","");
PlantInitialState = PlantInitialState.replace("\n","");
f.readline();
Notes = {};
for l in f:
n1 = l[0:5];
n2 = l[9];
Notes[n1] = n2;
print(l, end="");
#append to the beginning and the end an a=4 amount of pots
#store the amount of appended pots
PlantInitialState = "...." + PlantInitialState + "....";
a = 4;
PlantCurrentState = PlantInitialState;
part1 = 0;
for g in range(generationnumber2):
substate = PlantCurrentState[0:2];
substate += Notes.get(PlantCurrentState[0:5]);
for p in range(3,len(PlantCurrentState)-2):
substate += Notes.get(PlantCurrentState[p-2:p+3]);
substate += PlantCurrentState[-2:];
if(substate[2] == '#'):
substate = ".." + substate;
a += 2;
if(substate[-3] == '#'):
substate = substate + "..";
PlantCurrentState = substate;
if (g == generationnumber1 -1):
for pot in range(len(PlantCurrentState)):
if PlantCurrentState[pot] == '#':
part1 += pot - a;
SteadyState10k = 0;
for pot in range(len(PlantCurrentState)):
if PlantCurrentState[pot] == '#':
SteadyState10k += pot - a;
gendiv = generationnumber3//generationnumber2;
part2 = SteadyState10k*(gendiv);
print("part1: ", part1);
print("part2: ", part2);
#2830 too low
|