diff options
author | Marvin Borner | 2022-12-01 06:30:54 +0100 |
---|---|---|
committer | Marvin Borner | 2022-12-01 06:33:16 +0100 |
commit | 7dc8aaa7f8e17a74c0b0c59690ac9737395452d8 (patch) | |
tree | fd231869d5e57fa34eb5abf881692c0d3661f3a1 /2022/01/solve.py | |
parent | 0cb7f8aa21366172d1cc9aaa4ff1ce2ced21fa37 (diff) |
Improvements
Diffstat (limited to '2022/01/solve.py')
-rw-r--r-- | 2022/01/solve.py | 21 |
1 files changed, 8 insertions, 13 deletions
diff --git a/2022/01/solve.py b/2022/01/solve.py index de9aea8..7ad0cf7 100644 --- a/2022/01/solve.py +++ b/2022/01/solve.py @@ -1,27 +1,22 @@ -data = [block.split("\n") for block in open("input").read().split("\n\n")] +data = [[int(calory) for calory in block.split("\n") if calory != ''] for block in open("input").read().split("\n\n")] # i don't know list comprehension def part1(): res = 0 for block in data: - sum = 0 - for calory in block: - if len(calory) > 0: - sum += int(calory) - if sum > res: - res = sum + s = sum(block) + if s > res: + res = s return res def part2(): top3 = [0,0,0] for block in data: - s = 0 - for calory in block: - if len(calory) > 0: - s += int(calory) - if s > min(top3): - top3.remove(min(top3)) + s = sum(block) + m = min(top3) + if s > m: + top3.remove(m) top3.append(s) return sum(top3) |