Skip to content

Instantly share code, notes, and snippets.

@Mu-adventofcode
Created April 30, 2022 20:12
Show Gist options
  • Save Mu-adventofcode/f7e15448f1252e6ce5eb8252a8998f7f to your computer and use it in GitHub Desktop.
Save Mu-adventofcode/f7e15448f1252e6ce5eb8252a8998f7f to your computer and use it in GitHub Desktop.
Advent of Code 2021 day 07 part 1
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