Created
April 30, 2022 20:12
-
-
Save Mu-adventofcode/f7e15448f1252e6ce5eb8252a8998f7f to your computer and use it in GitHub Desktop.
Advent of Code 2021 day 07 part 1
This file contains hidden or 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
def parse_input(filename): | |
with open(filename) as fin: | |
line = fin.read().strip() | |
return [int(p) for p in line.split(",")] | |
def fuel_use(positions): | |
return min( | |
sum(abs(p - end_pos) for p in positions) | |
for end_pos in range(min(positions), max(positions)) | |
) | |
if __name__ == "__main__": | |
print(fuel_use(parse_input("input.txt"))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment