diff --git a/2021/day7/7a.py b/2021/day7/7a.py new file mode 100644 index 0000000..e7dc9aa --- /dev/null +++ b/2021/day7/7a.py @@ -0,0 +1,17 @@ +positions = [int(i) for i in open("input.txt", 'r').read().split(",")] + +width = max(positions) +bestFuel = len(positions)*width +bestPos = 0 + +for i in range(bestFuel): + fuelUsed = 0 + for pos in positions: + fuelUsed += abs(i - pos) + if fuelUsed > bestFuel: + break + bestFuel = fuelUsed + bestPos = i + +print(bestFuel) +print(bestPos) diff --git a/2021/day7/input.txt.sample b/2021/day7/input.txt.sample new file mode 100644 index 0000000..18bd32a --- /dev/null +++ b/2021/day7/input.txt.sample @@ -0,0 +1 @@ +16,1,2,0,4,2,7,1,2,14