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
|
import sys
|
||||||
|
|
||||||
if __name__ == '__main__':
|
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):
|
def calc(movement_cost):
|
||||||
return min([
|
return min(
|
||||||
sum(f(abs(crab-i)) for crab in inp)
|
sum(movement_cost(abs(position-target)) for position in positions)
|
||||||
for i in range(min(inp), max(inp)+1)
|
for target in range(min(positions), max(positions)+1)
|
||||||
])
|
)
|
||||||
|
|
||||||
print(calc(lambda n: n))
|
print(calc(lambda n: n))
|
||||||
print(calc(lambda n: n * (n+1)//2))
|
print(calc(lambda n: n * (n+1)//2))
|
||||||
|
|
Loading…
Reference in a new issue