diff options
| author | nekineki <nekineki@nekineki.net> | 2022-12-01 19:25:34 +0100 |
|---|---|---|
| committer | nekineki <nekineki@nekineki.net> | 2022-12-03 11:15:55 +0100 |
| commit | 5a52cac2a3a9fa154d339834c46aa7cbed25f328 (patch) | |
| tree | f2c8da494dfb14bbd159d1461ee77c8e96dfb752 /2022/day1/day1.py | |
| parent | 296e8c6ec939355b2eb0caabac2ade311506ce38 (diff) | |
day1
Diffstat (limited to '2022/day1/day1.py')
| -rwxr-xr-x | 2022/day1/day1.py | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/2022/day1/day1.py b/2022/day1/day1.py new file mode 100755 index 0000000..cf2ca85 --- /dev/null +++ b/2022/day1/day1.py @@ -0,0 +1,23 @@ +#!/usr/bin/env python3 + +arr = [] +s = 0 +with open("input.txt") as f: + for line in f: + line = line.strip() + if line == '': + arr.append(s) + s = 0 + else: + s += int(line) + if s != 0: + arr.append(s) + s = 0 + +# print(arr) +print(max(arr)) + +arr = sorted(arr, key=lambda x: -x) +print(sum(arr[:3])) + + |
