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-d11-p2.py | 108 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 108 insertions(+) create mode 100755 2018/aoc2018-d11-p2.py (limited to '2018/aoc2018-d11-p2.py') diff --git a/2018/aoc2018-d11-p2.py b/2018/aoc2018-d11-p2.py new file mode 100755 index 0000000..dbfafe7 --- /dev/null +++ b/2018/aoc2018-d11-p2.py @@ -0,0 +1,108 @@ +#advent of code 2018 +#day 11 +#part 2 +#too lazy to clean up the code, might do it later (i.e. never) + +#setup +GridSize = 300; +SquareSize = 3; +fcserialnumber = int(open("input.txt",'r').readline()); + +testing = False; +#testing = True; +if testing: + fcserialnumber = 42; #18=>90,269,16 ; 42 => 21,61; + +class fuelcell: + def __init__(self, x, y, serialnumber): + self.positionX = x; + self.positionY = y; + self.rackID = self.positionX + 10; + self.powerlevel = self.rackID * self.positionY; + self.powerlevel += serialnumber; + self.powerlevel *= self.rackID; + self.powerlevel = self.powerlevel//100; + self.powerlevel = self.powerlevel%10; + self.powerlevel -= 5; + def coords(self): + print(f'Fuel Cell coordinates (x,y): {self.positionX},{self.positionY} '); + def __str__(self): + return f'{self.powerlevel}'; + +''' +testinput = [[3,5,8],[122,79,57],[217,196,39],[101,153,71]]; + +for t in testinput: + dummycell = fuelcell(t[0],t[1],t[2]); + print(t, " -> ",dummycell.powerlevel); + dummycell.coords(); + +print("#############################"); +print(); +''' + +fcgrid = []; +gridline = []; + +print("#############################"); +print("INITIATE BATTERY ARRAY"); +for Y in range(GridSize): + gridline.clear(); + for X in range(GridSize): + gridline.append(fuelcell(X+1,Y+1,fcserialnumber)); + fcgrid.append(gridline.copy()); + +print("#############################"); +print("CALCULATE SQUARE SUBSUMS"); +sumtable = []; + +gridline.clear(); +gridline.append(fcgrid[0][0].powerlevel); + +for X in range(1,GridSize): + SubSumFc = fcgrid[0][X].powerlevel + gridline[X-1]; + gridline.append(SubSumFc); +sumtable.append(gridline.copy()); + +currentsubsum = 0; + +for Y in range(1,GridSize): + gridline.clear(); + SubSumFc = sumtable[Y-1][0] + fcgrid[Y][0].powerlevel; + gridline.append(SubSumFc); + currentsubsum = fcgrid[Y][0].powerlevel; + for X in range(1,GridSize): + currentsubsum += fcgrid[Y][X].powerlevel; + gridline.append(sumtable[Y-1][X] + currentsubsum); + sumtable.append(gridline.copy()); + +print("#############################"); +print("SEARCH FOR HIGHEST SUBSUM SQUARE"); + +maxpower = -999; +maxX = 0; +maxY = 0; +powernow = 0; +maxsquare = 0; + +for Y in range(1,GridSize-3): + ssy = GridSize - Y; + for X in range(1,GridSize-3): + ssx = GridSize - X; + SquareSize = (ssx>=ssy)*ssy + ssx*(ssx maxpower): + maxX = X; + maxY = Y; + maxpower = powernow; + maxsquare = s; + #print("new max power: ", maxpower, " // ", powernow); + +print("#############################"); +print("Results:"); +print(maxX, "\t", maxY, "\t", maxsquare, "\t", maxpower); +fcgrid[maxY][maxX].coords(); +print("winrar part 2:\t", fcgrid[maxY][maxX].positionX,",",fcgrid[maxY][maxX].positionY,",",maxsquare+1,end=""); + -- cgit v1.2.3