123456789101112131415161718 |
- import statistics
- from util import get_input
- input = get_input("7.input")
- crabs = [int(a) for a in input[0].split(",")]
- median = statistics.median(crabs)
- print(sum([abs(a - median) for a in crabs]))
- maxpos = max(crabs)
- def movecost(a, b):
- n = abs(a - b)
- return (n * (n + 1)) / 2
- print(min([sum([movecost(a, target) for a in crabs]) for target in range(maxpos + 1)]))
|