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-p1.py | 75 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 75 insertions(+) create mode 100755 2018/aoc2018-d11-p1.py (limited to '2018/aoc2018-d11-p1.py') diff --git a/2018/aoc2018-d11-p1.py b/2018/aoc2018-d11-p1.py new file mode 100755 index 0000000..2379c3c --- /dev/null +++ b/2018/aoc2018-d11-p1.py @@ -0,0 +1,75 @@ +#advent of code 2018 +#day 11 +#part 1 + +#setup +GridSize = 300; +SquareSize = 3; +fcserialnumber = int(open("input.txt",'r').readline()); + +testing = False; +#testing = True; +if testing: + fcserialnumber = 42; #18=>33,45 ; 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 = []; + +for Y in range(GridSize): + gridline.clear(); + for X in range(GridSize): + gridline.append(fuelcell(X+1,Y+1,fcserialnumber)); + fcgrid.append(gridline.copy()); + +maxpower = -999; #negative power just to start the algorythm +maxX = 0; +maxY = 0; +powernow = 0; + +for Y in range(GridSize-SquareSize+1): + for X in range(GridSize-SquareSize+1): + powernow = 0; + for sy in range(SquareSize): + for sx in range(SquareSize): + powernow += fcgrid[Y+sy][X+sx].powerlevel; + if (powernow > maxpower): + maxpower = powernow; + maxX = X; + maxY = Y; + +#print(f'maximum found: {maxX},{maxY} => {maxpower}'); +print("part 1: "); +fcgrid[maxY][maxX].coords(); + +#10,300 wrong +#9,0 wrong +#0,9 wrong +#33,45 -- cgit v1.2.3