Du kannst nicht mehr als 25 Themen auswählen Themen müssen mit entweder einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

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