From 60fd5e5b7799011de864417489c0f0a3eb1657e3 Mon Sep 17 00:00:00 2001 From: Ryad MEHIRI Date: Wed, 21 Oct 2026 10:57:35 +0200 Subject: [PATCH] =?UTF-8?q?F9=20:=20d=C3=A9couper=20categorie=20pour=20ram?= =?UTF-8?q?ener=20M=20de=2014=20=C3=A0=205?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit categorie enchaînait 13 décisions (if imbriqués, || et &&) : M = 14, au-dessus de l'objectif M <= 10. Elle est découpée par sens de l'opération : categorie (M = 3), categorie_debit (M = 5), categorie_credit (M = 5), categorie_gros_credit (M = 3), plus le prédicat est_week_end (M = 1) qui remplace les tests jour % 7 == 5 || jour % 7 == 6 et jour % 7 < 5. Mêmes catégories sur tout le domaine (montant de -50 000 à 50 000, jour % 210, client % 10 : 210 millions de combinaisons testées). Complexité inchangée (O(1)). Empreinte inchangée (ff68d260a7a58441). Co-Authored-By: Claude Opus 5.5 --- banque.c | 65 +++++++++++++++++++++++++++++++------------------------- 1 file changed, 36 insertions(+), 29 deletions(-) diff --git a/banque.c b/banque.c index 6180c2f..68b57e4 100644 --- a/banque.c +++ b/banque.c @@ -213,38 +213,45 @@ long nb_facons_rendre(int somme, int nb_pieces) return resultat; } -/* F9 : catégorie d'une transaction (pour les statistiques) */ +/* F9 : catégorie d'une transaction (pour les statistiques), découpée par + * sens de l'opération pour que chaque fonction reste simple (M <= 5). */ +int est_week_end(int jour) +{ + return jour % 7 >= 5; /* jours 5 et 6 de la semaine (jour >= 0) */ +} + +int categorie_debit(const Transaction *t) /* montant < 0 */ +{ + if (t->montant < -20000) + return est_week_end(t->jour) ? 1 : 2; + if (t->montant < -5000) + return 3; + return t->client % 10 == 0 ? 4 : 5; +} + +int categorie_gros_credit(const Transaction *t) /* montant > 30000 */ +{ + return t->client % 10 == 0 && !est_week_end(t->jour) ? 6 : 7; +} + +int categorie_credit(const Transaction *t) /* montant > 0 */ +{ + if (t->montant > 30000) + return categorie_gros_credit(t); + if (t->montant > 10000) + return 8; + if (t->montant > 1000) + return t->jour % 30 == 0 ? 9 : 10; + return 11; +} + int categorie(const Transaction *t) { - if (t->montant < 0) { - if (t->montant < -20000) { - if (t->jour % 7 == 5 || t->jour % 7 == 6) - return 1; - else - return 2; - } else if (t->montant < -5000) { - return 3; - } else { - if (t->client % 10 == 0) - return 4; - return 5; - } - } else if (t->montant == 0) { + if (t->montant < 0) + return categorie_debit(t); + if (t->montant == 0) return 0; - } else { - if (t->montant > 30000) { - if (t->client % 10 == 0 && t->jour % 7 < 5) - return 6; - return 7; - } else if (t->montant > 10000) { - return 8; - } else if (t->montant > 1000) { - if (t->jour % 30 == 0) - return 9; - return 10; - } - return 11; - } + return categorie_credit(t); } /* F10 : ajoute une ligne à la fin du rapport. On passe la position du '\0'