2021 day7/python: prettify
This commit is contained in:
parent
e9a47c1863
commit
4ea70f38ea
1 changed files with 6 additions and 6 deletions
|
@ -3,13 +3,13 @@
|
|||
import sys
|
||||
|
||||
if __name__ == '__main__':
|
||||
inp = [int(i) for i in sys.stdin.readline().split(',')]
|
||||
positions = [int(i) for i in sys.stdin.readline().split(',')]
|
||||
|
||||
def calc(f):
|
||||
return min([
|
||||
sum(f(abs(crab-i)) for crab in inp)
|
||||
for i in range(min(inp), max(inp)+1)
|
||||
])
|
||||
def calc(movement_cost):
|
||||
return min(
|
||||
sum(movement_cost(abs(position-target)) for position in positions)
|
||||
for target in range(min(positions), max(positions)+1)
|
||||
)
|
||||
|
||||
print(calc(lambda n: n))
|
||||
print(calc(lambda n: n * (n+1)//2))
|
||||
|
|
Loading…
Reference in a new issue