diff options
Diffstat (limited to '2018/aoc2018-d12.py')
-rw-r--r-- | 2018/aoc2018-d12.py | 68 |
1 files changed, 68 insertions, 0 deletions
diff --git a/2018/aoc2018-d12.py b/2018/aoc2018-d12.py new file mode 100644 index 0000000..9922c39 --- /dev/null +++ b/2018/aoc2018-d12.py @@ -0,0 +1,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 |