initial commit
This commit is contained in:
commit
27fe77bbe1
134 changed files with 21939 additions and 0 deletions
24
2021/Day7/Day7.py
Normal file
24
2021/Day7/Day7.py
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
import sys
|
||||
|
||||
|
||||
def calcFuelCost(steps: int):
|
||||
total = 0
|
||||
for cost in range(1, steps + 1):
|
||||
total += cost
|
||||
|
||||
return total
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
with open("input.txt", "r") as f:
|
||||
crabs = [int(x) for x in f.read().strip().split(",")]
|
||||
|
||||
minFuel = sys.maxsize
|
||||
for i in crabs:
|
||||
totalfuelcost = 0
|
||||
for x in crabs:
|
||||
totalfuelcost += calcFuelCost(abs(x - i))
|
||||
|
||||
minFuel = min(totalfuelcost, minFuel)
|
||||
|
||||
print(minFuel)
|
||||
Loading…
Add table
Add a link
Reference in a new issue