Last active
June 5, 2023 10:39
-
-
Save josfam/571e446b0d1d62a4ff7a2cbcf8d0d50d to your computer and use it in GitHub Desktop.
Accompanying code for Advent of Code 2022 Day 1: Calorie Counting Medium article
This file contains 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
sample_input = """ | |
1000 | |
2000 | |
3000 | |
4000 | |
5000 | |
6000 | |
7000 | |
8000 | |
9000 | |
10000 | |
""".strip().splitlines() | |
highest_elf_total = 0 | |
current_elf_total = 0 | |
for calorie in sample_input: | |
if calorie == '': # denotes next elf's input | |
highest_elf_total = max(highest_elf_total, current_elf_total) | |
current_elf_total = 0 # reset before reading the next elf's calories | |
else: | |
current_elf_total += int(calorie) | |
print(highest_elf_total) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment