Advent of Code 2022 https://adventofcode.com/2022
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

day1-2.py 506B

123456789101112131415161718
  1. # https://adventofcode.com/2022/day/1
  2. def main():
  3. with open("input1.txt", "r") as file:
  4. indata = file.read()
  5. elves = indata.split("\n\n")
  6. elf_cals = []
  7. for i, elf in enumerate(elves):
  8. cal_lines = [int(x) for x in elf.split("\n")]
  9. elf_cals.append((i,sum(cal_lines)))
  10. elf_cals_sorted = sorted(elf_cals, reverse=True, key=lambda x: x[1])
  11. most_snacks = elf_cals_sorted[:3]
  12. print(sum([x[1] for x in most_snacks]))
  13. if __name__ == "__main__":
  14. main()