Created
December 17, 2021 03:44
-
-
Save loudambiance/89ae33149c3f9e2c20bc2403353754c6 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
test = False | |
file = 'data/task7test.txt' if test else 'data/task7.txt' | |
with open(file) as f: | |
crabmarines = [int(x) for x in next(f).split(',')] | |
bestPosition = 9999999999 | |
for position in range(min(crabmarines),max(crabmarines)+1): | |
curPosition = sum(list(map(lambda x: abs(position-x)*((abs(position-x)+1)/2), crabmarines))) | |
if curPosition < bestPosition: | |
bestPosition = curPosition | |
print(bestPosition) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment