import statistics def main(): """ Find the position that requires the fewest total moves for each crab sub to get there. This yields to an insight: given a list of numbers, the value that requires the fewest total "moves" to get there is the median. """ with open("aoc7-1.txt", "r") as file: positions = [int(el) for el in file.read().strip().split(",")] med = statistics.median(positions) moves = [abs(pos-med) for pos in positions] print(sum(moves)) if __name__ == "__main__": main()