Add 2022 day 01

This commit is contained in:
augustin64 2022-12-01 18:11:23 +01:00
parent 7dce5d64a4
commit e802ba1c58
2 changed files with 31 additions and 0 deletions

3
.gitignore vendored Normal file
View File

@ -0,0 +1,3 @@
utils/cookie.txt
*/inputs

28
2022/day01.py Executable file
View File

@ -0,0 +1,28 @@
#!/usr/bin/python3
"""
Jour 01 du défi Advent Of Code pour l'année 2022
"""
def read_sample():
"""récupère les entrées depuis le fichier texte correspondant"""
with open('inputs/day01.txt', 'r') as f:
sample = f.read().split('\n\n')
sample = [ [int(j) for j in i.split("\n") if j != ''] for i in sample if i != '' ]
return sample
def part1(sample):
"""Partie 1 du défi"""
return max([sum(i) for i in sample])
def part2(sample):
"""Partie 2 du défi"""
sums = [sum(i) for i in sample]
sums.sort()
return sums[-1] + sums[-2] + sums[-3]
def main():
"""Fonction principale"""
sample = read_sample()
print(f"part1: {part1(sample)}")
print(f"part2: {part2(sample)}")