advent-of-code/2022/python/day01.py

33 lines
584 B
Python
Raw Normal View History

2022-12-09 16:43:00 +00:00
import shared
from pprint import pprint as pp
def run(rows):
elves = []
current_elf = 0
for row in rows:
2022-12-12 07:41:14 +00:00
if row == "":
2022-12-09 16:43:00 +00:00
elves.append(current_elf)
current_elf = 0
continue
current_elf += int(row)
three = 0
for x in range(3):
2022-12-12 07:41:14 +00:00
most = max(elves)
idx = elves.index(most)
elves.pop(idx)
three += most
2022-12-09 16:43:00 +00:00
print(three)
def main():
with open(shared.get_fname(1), "r") as f:
rows = [x.rstrip() for x in f.readlines()]
run(rows)
if __name__ == "__main__":
main()