parent
8a13d3912c
commit
19a76fb3cb
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(",")] |
||||
|
||||
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 |
||||
|
||||
for i in range(bestFuel): |
||||
fuelUsed = 0 |
||||
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: |
||||
break |
||||
bestFuel = fuelUsed |
Loading…
Reference in new issue