day 1: python

This commit is contained in:
Felix Pankratz 2022-12-01 18:13:18 +01:00
parent bf735e1527
commit 14879c0d73
4 changed files with 2299 additions and 0 deletions

18
2022/01/01.py Executable file
View File

@ -0,0 +1,18 @@
#!/usr/bin/env python3
INPUT_FILE = 'input'
def main():
content = list(map(str.strip, open(INPUT_FILE, 'r').readlines()))
elfs = []
cal_sum = 0
for line in content:
if line == '':
elfs.append(cal_sum)
cal_sum = 0
continue
cal_sum += int(line)
print(max(elfs))
if __name__ == '__main__':
main()

18
2022/01/02.py Executable file
View File

@ -0,0 +1,18 @@
#!/usr/bin/env python3
INPUT_FILE = 'input'
def main():
content = list(map(str.strip, open(INPUT_FILE, 'r').readlines()))
elfs = []
cal_sum = 0
for line in content:
if line == '':
elfs.append(cal_sum)
cal_sum = 0
continue
cal_sum += int(line)
elfs.sort()
print(sum(elfs[-3:]))
if __name__ == '__main__':
main()

2254
2022/01/input Executable file

File diff suppressed because it is too large Load Diff

9
2022/template.py Executable file
View File

@ -0,0 +1,9 @@
#!/usr/bin/env python3
INPUT_FILE = 'input'
def main():
with open(INPUT_FILE, 'r') as f:
if __name__ == '__main__':
main()