Advertisement
Syldarion

AdventOfCode'22-Day1

Nov 30th, 2022 (edited)
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.60 KB | None | 0 0
  1. def get_elf_calories(file_path):
  2. calories = []
  3. with open(file_path, "r") as f:
  4. line = f.readline()
  5. current_sum = 0
  6. while line:
  7. if not line.strip():
  8. calories.append(current_sum)
  9. current_sum = 0
  10. else:
  11. current_sum += int(line)
  12. line = f.readline()
  13. return calories
  14.  
  15.  
  16. def part1(*args):
  17. calories = get_elf_calories(args[0])
  18. return max(calories)
  19.  
  20.  
  21. def part2(*args):
  22. calories = get_elf_calories(args[0])
  23. calories.sort(reverse=True)
  24. return sum(calories[:3])
  25.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement