Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Open the input file
- with open("input.txt", "r") as input_file:
- # Read the input
- calories = []
- current_elf_calories = []
- for line in input_file:
- line = line.strip()
- if line == "":
- # Empty line, start a new list of calories for the next Elf
- calories.append(current_elf_calories)
- current_elf_calories = []
- else:
- # Non-empty line, add the number of calories to the current Elf's list
- current_elf_calories.append(int(line))
- # Add the last Elf's calories to the list (if any)
- if current_elf_calories:
- calories.append(current_elf_calories)
- # Find the total number of calories for each Elf
- totals = [sum(c) for c in calories]
- # Find the maximum number of calories and print the result
- max_calories = max(totals)
- print(max_calories)
Advertisement
Add Comment
Please, Sign In to add comment