From aaf069f1a979ec5e45d8355c91796ae31d49b30e Mon Sep 17 00:00:00 2001 From: augustin64 Date: Sun, 10 Dec 2023 15:29:11 +0100 Subject: [PATCH] Update 2023 solvers according to template change --- 2023/day01.py | 4 +++- 2023/day02.py | 17 +++++++++-------- 2023/day03.py | 4 +++- 2023/day04.py | 4 +++- 2023/day05.py | 4 +++- 2023/day06.py | 4 +++- 2023/day07.py | 5 +++-- 2023/day08.py | 18 +++++++++--------- 2023/day09.py | 4 +++- 2023/day10.py | 4 +++- 10 files changed, 42 insertions(+), 26 deletions(-) diff --git a/2023/day01.py b/2023/day01.py index 9f6f1e2..36a2ba4 100755 --- a/2023/day01.py +++ b/2023/day01.py @@ -2,10 +2,12 @@ """ Jour 01 du défi Advent Of Code pour l'année 2023 """ +import os def read_sample(): """récupère les entrées depuis le fichier texte correspondant""" - with open('inputs/day01.txt', 'r') as f: + filename = os.path.join(os.path.dirname(__file__ ), "inputs", "day01.txt") + with open(filename, 'r') as f: sample = f.read().split('\n') sample = [ i for i in sample if i != '' ] return sample diff --git a/2023/day02.py b/2023/day02.py index 68a6694..9c19a30 100755 --- a/2023/day02.py +++ b/2023/day02.py @@ -2,6 +2,15 @@ """ Jour 02 du défi Advent Of Code pour l'année 2023 """ +import os + +def read_sample(): + """récupère les entrées depuis le fichier texte correspondant""" + filename = os.path.join(os.path.dirname(__file__ ), "inputs", "day02.txt") + with open(filename, 'r') as f: + sample = f.read().split('\n') + sample = [ i.split(": ")[1] for i in sample if i != '' ] + return sample class Tirage(): def __init__(self, tirage): @@ -22,14 +31,6 @@ class Tirage(): def __repr__(self): return f"r{self.red}g{self.green}b{self.blue}" - -def read_sample(): - """récupère les entrées depuis le fichier texte correspondant""" - with open('inputs/day02.txt', 'r') as f: - sample = f.read().split('\n') - sample = [ i.split(": ")[1] for i in sample if i != '' ] - return sample - def parse_tirage(tirage): tirage.split(", ") diff --git a/2023/day03.py b/2023/day03.py index beacf37..b252c0e 100755 --- a/2023/day03.py +++ b/2023/day03.py @@ -2,10 +2,12 @@ """ Jour 03 du défi Advent Of Code pour l'année 2023 """ +import os def read_sample(): """récupère les entrées depuis le fichier texte correspondant""" - with open('inputs/day03.txt', 'r') as f: + filename = os.path.join(os.path.dirname(__file__ ), "inputs", "day03.txt") + with open(filename, 'r') as f: sample = f.read().split('\n') sample = [ i for i in sample if i != '' ] return sample diff --git a/2023/day04.py b/2023/day04.py index 3ad6e0c..c61169c 100755 --- a/2023/day04.py +++ b/2023/day04.py @@ -2,10 +2,12 @@ """ Jour 04 du défi Advent Of Code pour l'année 2023 """ +import os def read_sample(): """récupère les entrées depuis le fichier texte correspondant""" - with open('inputs/day04.txt', 'r') as f: + filename = os.path.join(os.path.dirname(__file__ ), "inputs", "day04.txt") + with open(filename, 'r') as f: sample = f.read().split('\n') sample = [ i for i in sample if i != '' ] return sample diff --git a/2023/day05.py b/2023/day05.py index c7eb7da..e1a368b 100755 --- a/2023/day05.py +++ b/2023/day05.py @@ -2,10 +2,12 @@ """ Jour 05 du défi Advent Of Code pour l'année 2023 """ +import os def read_sample(): """récupère les entrées depuis le fichier texte correspondant""" - with open('inputs/day05.txt', 'r') as f: + filename = os.path.join(os.path.dirname(__file__ ), "inputs", "day05.txt") + with open(filename, 'r') as f: sample = f.read().split('\n\n') sample = [ i for i in sample if i != '' ] return sample diff --git a/2023/day06.py b/2023/day06.py index 983237d..1d9ee04 100755 --- a/2023/day06.py +++ b/2023/day06.py @@ -2,10 +2,12 @@ """ Jour 06 du défi Advent Of Code pour l'année 2023 """ +import os def read_sample(): """récupère les entrées depuis le fichier texte correspondant""" - with open('inputs/day06.txt', 'r') as f: + filename = os.path.join(os.path.dirname(__file__ ), "inputs", "day06.txt") + with open(filename, 'r') as f: sample = f.read().split('\n') sample = [ i for i in sample if i != '' ] return sample diff --git a/2023/day07.py b/2023/day07.py index ed5a46f..17a7fc5 100755 --- a/2023/day07.py +++ b/2023/day07.py @@ -3,11 +3,12 @@ Jour 07 du défi Advent Of Code pour l'année 2023 """ from functools import cmp_to_key - +import os def read_sample(): """récupère les entrées depuis le fichier texte correspondant""" - with open('inputs/day07.txt', 'r') as f: + filename = os.path.join(os.path.dirname(__file__ ), "inputs", "day07.txt") + with open(filename, 'r') as f: sample = f.read().split('\n') sample = [ (i.split(" ")[0], i.split(" ")[1]) for i in sample if i != '' ] return sample diff --git a/2023/day08.py b/2023/day08.py index 24d6e09..dbd3dba 100755 --- a/2023/day08.py +++ b/2023/day08.py @@ -2,6 +2,15 @@ """ Jour 08 du défi Advent Of Code pour l'année 2023 """ +import os + +def read_sample(): + """récupère les entrées depuis le fichier texte correspondant""" + filename = os.path.join(os.path.dirname(__file__ ), "inputs", "day08.txt") + with open(filename, 'r') as f: + sample = f.read().split('\n') + sample = [ i for i in sample if i != '' ] + return sample def gcd(a, b): while b: @@ -17,15 +26,6 @@ def lcm_of_list(numbers): result = lcm(result, num) return result - - -def read_sample(): - """récupère les entrées depuis le fichier texte correspondant""" - with open('inputs/day08.txt', 'r') as f: - sample = f.read().split('\n') - sample = [ i for i in sample if i != '' ] - return sample - def parse_sample(sample): instructions = sample[0] mappings = { diff --git a/2023/day09.py b/2023/day09.py index 7c27a42..2f9ceb7 100755 --- a/2023/day09.py +++ b/2023/day09.py @@ -2,10 +2,12 @@ """ Jour 09 du défi Advent Of Code pour l'année 2023 """ +import os def read_sample(): """récupère les entrées depuis le fichier texte correspondant""" - with open('inputs/day09.txt', 'r') as f: + filename = os.path.join(os.path.dirname(__file__ ), "inputs", "day09.txt") + with open(filename, 'r') as f: sample = f.read().split('\n') sample = [ [int(j) for j in i.split()] for i in sample if i != '' ] return sample diff --git a/2023/day10.py b/2023/day10.py index 6ca9d40..18a7fa8 100755 --- a/2023/day10.py +++ b/2023/day10.py @@ -2,10 +2,12 @@ """ Jour 10 du défi Advent Of Code pour l'année 2023 """ +import os def read_sample(): """récupère les entrées depuis le fichier texte correspondant""" - with open('inputs/day10.txt', 'r') as f: + filename = os.path.join(os.path.dirname(__file__ ), "inputs", "day10.txt") + with open(filename, 'r') as f: sample = f.read().split('\n') sample = [ [j for j in i] for i in sample if i != '' ] return sample