parent
57344eebea
commit
f6d06f1ffa
1 changed files with 4 additions and 2 deletions
@ -1,13 +1,15 @@ |
|||||||
positions = [int(i) for i in open("input.txt", 'r').read().split(",")] |
positions = [int(i) for i in open("input.txt", 'r').read().split(",")] |
||||||
|
|
||||||
width = max(positions) |
width = max(positions) |
||||||
bestFuel = len(positions)*width |
part = input("a or b? ") |
||||||
|
bestFuel = len(positions)*width if part == "a" else len(positions)* int(((width ** 2 + width) / 2)) |
||||||
bestPos = 0 |
bestPos = 0 |
||||||
|
|
||||||
for i in range(bestFuel): |
for i in range(bestFuel): |
||||||
fuelUsed = 0 |
fuelUsed = 0 |
||||||
for pos in positions: |
for pos in positions: |
||||||
fuelUsed += abs(i - pos) |
mov = abs(i - pos) |
||||||
|
fuelUsed += mov if part == "a" else int(((mov ** 2 + mov) / 2)) |
||||||
if fuelUsed > bestFuel: |
if fuelUsed > bestFuel: |
||||||
break |
break |
||||||
bestFuel = fuelUsed |
bestFuel = fuelUsed |
Loading…
Reference in new issue