You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
20 lines
482 B
20 lines
482 B
2 years ago
|
positions = [int(i) for i in open("input.txt", 'r').read().split(",")]
|
||
|
|
||
|
width = max(positions)
|
||
2 years ago
|
part = input("a or b? ")
|
||
|
bestFuel = len(positions)*width if part == "a" else len(positions)* int(((width ** 2 + width) / 2))
|
||
2 years ago
|
bestPos = 0
|
||
|
|
||
|
for i in range(bestFuel):
|
||
|
fuelUsed = 0
|
||
|
for pos in positions:
|
||
2 years ago
|
mov = abs(i - pos)
|
||
|
fuelUsed += mov if part == "a" else int(((mov ** 2 + mov) / 2))
|
||
2 years ago
|
if fuelUsed > bestFuel:
|
||
|
break
|
||
|
bestFuel = fuelUsed
|
||
|
bestPos = i
|
||
|
|
||
|
print(bestFuel)
|
||
|
print(bestPos)
|