diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..f8aaf49 --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +utils/cookie.txt + +*/inputs \ No newline at end of file diff --git a/2022/day01.py b/2022/day01.py new file mode 100755 index 0000000..37152ae --- /dev/null +++ b/2022/day01.py @@ -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)}")