day 1: python
This commit is contained in:
parent
bf735e1527
commit
14879c0d73
18
2022/01/01.py
Executable file
18
2022/01/01.py
Executable 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
18
2022/01/02.py
Executable 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
2254
2022/01/input
Executable file
File diff suppressed because it is too large
Load Diff
9
2022/template.py
Executable file
9
2022/template.py
Executable 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()
|
Loading…
Reference in New Issue
Block a user