◂ 6 décembre 2025 ▸
Trash Compactor : Faire des sommes ou des produits selon une liste, mais avec parsing par colonne de nombre (partie 1) ou de chiffre (partie 2) de l'input
836 7512 183 … 3 43
183 685 317 … 979 57
26 319 36 … 813 49
22 51 63 … 849 51
+ * * … + *
- code.py
- dict_fonctions.diffy
from math import prod from math import prod
> FONCTIONS = {'+': sum, '*': prod}
… …
### Partie 1 #### ### Partie 1 ####
tokens = [line.split() for line in lines[:-1]] tokens = [line.split() for line in lines[:-1]]
operators = lines[-1].split() operators = lines[-1].split()
rep1 = 0 rep 1 = 0
for i, operator in enumerate(operators): for i, operator in enumerate(operators):
operation_values = [int(line[i]) for line in tokens] operation_values = [int(line[i]) for line in tokens]
if operator == '+': | rep1 += FONCTIONS[operator](operation_values)
rep1 += sum(operation_values) <
else: <
rep1 += prod(operation_values) <
print("Réponse partie 1:", rep1) print("Réponse partie 1:", rep1)