1
0
Fork 0
adventofcode/2022/01/main.py

46 lines
1 KiB
Python
Raw Permalink Normal View History

2024-12-09 22:33:16 +00:00
#!/usr/bin/env python
# -*- encoding: utf-8; py-indent-offset: 4 -*-
# Author: Sebastian Mark
# CC-BY-SA (https://creativecommons.org/licenses/by-sa/4.0/deed.de)
# pylint: disable=missing-module-docstring,missing-function-docstring,consider-using-f-string
def readinput():
with open("input", "r", encoding="utf-8") as file:
lines = []
for line in file.read().splitlines():
lines.append(int(line) if line.isdigit() else "")
lines.append("")
return lines
def sum_carried_calories(calories: list) -> list:
maxcals = []
cur = 0
for cal in calories:
if cal != "":
cur += cal
else:
maxcals.append(cur)
cur = 0
return maxcals
def main():
calories = readinput()
carried = sum_carried_calories(calories)
# part1
maxcarried = max(carried)
print("Max carried calories: %d" % maxcarried)
# part2
topthree = sum(sorted(carried, reverse=True)[:3])
print("Max 3 carried calories: %d" % topthree)
if __name__ == "__main__":
main()