1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
|
%%%
% Defi Table
%%%
\setKVdefault[DefiTable]{Solution=false,Math=false,LargeurT=5mm,Graines=false,Creation=false,ValeurMin=1,ValeurMax=10,Restreint=false}
\defKV[DefiTable]{Graine=\setKV[DefiTable]{Graines}}%
\NewDocumentCommand\MelangeListeNew{mm}{%
% #1 Liste à mélanger
% #2 Nombre d'éléments à conserver
\setsepchar[*]{/}\ignoreemptyitems%
\readlist*\ListeInter{#1}%
\xdef\faa{}% Liste construite
\xdef\fii{}% Liste détruite
% on crée les #2 premieres solutions.
\xintFor* ##1 in {\xintSeq{1}{#2}}\do{%
\xintifboolexpr{\ListeInterlen>1}{%
\xdef\Alea{\fpeval{randint(\ListeInterlen)}}%
\xdef\faa{\faa \ListeInter[\Alea]/}%
\xdef\fii{}%
\xintFor* ##2 in {\xintSeq{1}{\ListeInterlen}}\do{%
\xintifboolexpr{##2 == \Alea}{%
}{%
\xdef\fii{\fii \ListeInter[##2]/}%
}%
}%
}{%
\xdef\faa{\faa \ListeInter[1]}%
}%
\readlist*\ListeInter{\fii}%
}%
\reademptyitems%
}%
\NewDocumentCommand\JeConstruisLesProduits{mm}{%
\xintFor* ##1 in{\xintSeq{#1}{#2}}\do{%
\xintifForFirst{%
\xdef\ListeDesProduitsFoo{\fpeval{##1}}%
\xintFor* ##2 in{\xintSeq{2}{10}}\do{%
\xdef\ListeDesProduitsFoo{\ListeDesProduitsFoo/\fpeval{##1*##2}}%
}%
}{%
\xintFor* ##2 in{\xintSeq{1}{10}}\do{%
\xdef\JeCoupe{0}%
\xintFor* ##3 in{\xintSeq{#1}{\fpeval{##1-1}}}\do{%
\xintifboolexpr{\fpeval{##1*##2}>\fpeval{##3*10}}{}{%
\modulo{\fpeval{##1*##2}}{##3}\relax%
\xintifboolexpr{\remainder==0}{\xdef\JeCoupe{1}\xintBreakFor}{}%
}%
}%
\xintifboolexpr{\JeCoupe==1}{}{\xdef\ListeDesProduitsFoo{\ListeDesProduitsFoo/\fpeval{##1*##2}}}%
}%
}%
}%
\setsepchar[*]{/}%
\readlist*\ListeDesProduits{\ListeDesProduitsFoo}%
\xdef\NombreDeProduitATester{\ListeDesProduitslen}%
}%
\NewDocumentCommand\DefiTableNombreLettreduCode{m}{%
\JeConstruisLesProduits{\useKV[DefiTable]{ValeurMin}}{\useKV[DefiTable]{ValeurMax}}%
\MelangeListeNew{\ListeDesProduitsFoo}{\NombreDeProduitATester}%
% Les produits mélangés sont :\par
\readlist*\ListeDesProduits{\faa}%
\xdef\ListeDesCaracteresFoo{a/b/c/d/e/f/g/h/i/j/k/l/m/n/o/p/q/r/s/t/u/v/w/x/y/z/à/é/è/ê/ï/î/ô/ö/ù/ç/A/B/C/D/E/F/G/H/I/J/K/L/M/N/O/P/Q/R/S/T/U/V/W/X/Y/Z/À/É/È/,/$?$/$;$/./$!$/$:$/-}%
\savecomparemode%
\comparestrict%
\xdef\PfCFooDepart{}%
\StrLen{#1}[\LongueurMot]%
\xintFor* ##1 in{\xintSeq{1}{\LongueurMot}}\do{%
\StrChar{#1}{##1}[\LettreMot]%
\xdef\PfCFooDepart{\PfCFooDepart \LettreMot/}%
}%
\setsepchar[*]{/}\reademptyitems%
\readlist*\ListeDesLettres{\PfCFooDepart}%
\xdef\PfCFooArrivee{\ListeDesLettres[1]}%
\xintFor* ##1 in{\xintSeq{2}{\LongueurMot}}\do{%
\StrCompare{\ListeDesLettres[##1]}{\\}[\PfCRetiensEtoile]%
\StrCompare{\ListeDesLettres[##1]}{ }[\PfCRetiensPara]%
\xintifboolexpr{\PfCRetiensEtoile==0 || \PfCRetiensPara==0}{}{%
\xdef\PfCTotal{0}%
\xintFor* ##2 in{\xintSeq{1}{\fpeval{##1-1}}}\do{%
\StrCompare{\ListeDesLettres[##1]}{\ListeDesLettres[##2]}[\PfCRetiens]%
\xdef\PfCTotal{\fpeval{\PfCTotal+\PfCRetiens}}%
}%
\xintifboolexpr{\PfCTotal==\fpeval{##1-1}}{\xdef\PfCFooArrivee{\PfCFooArrivee/\ListeDesLettres[##1]}}{}%
}%
}%
%Arrivee = \PfCFooArrivee\par
\setsepchar[*]{/}\ignoreemptyitems%
\readlist*\ListeDesLettresUniques{\PfCFooArrivee}%
%La liste des lettres uniques ainsi créée :\par
%\showitems\ListeDesLettresUniques[]%
% Il faut retirer les lettres uniques de la liste des caracteres
\readlist*\ListeTotaleDesCaracteres{\ListeDesCaracteresFoo}%
%\par
%La liste totale des caractères est :\par
%\showitems\ListeTotaleDesCaracteres[]
%\par
\xdef\ListeCaracteresUniques{}%
\xintFor* ##1 in{\xintSeq{1}{\ListeTotaleDesCaractereslen}}\do{%
%Le caractère testé est \ListeTotaleDesCaracteres[##1]. On le compare à :%
\xdef\PfCTotal{0}%
\xintFor* ##2 in{\xintSeq{1}{\ListeDesLettresUniqueslen}}\do{%
\StrCompare{\ListeTotaleDesCaracteres[##1]}{\ListeDesLettresUniques[##2]}[\PfCRetiens]%
\xdef\PfCTotal{\fpeval{\PfCTotal+\PfCRetiens}}%
}%
\xintifboolexpr{\PfCTotal==\ListeDesLettresUniqueslen}{\xdef\ListeCaracteresUniques{\ListeCaracteresUniques\ListeTotaleDesCaracteres[##1]/}}{}%
}%
%La liste des caractères uniques à ajouter
\MelangeListeNew{\ListeCaracteresUniques}{\fpeval{\NombreDeProduitATester-\ListeDesLettresUniqueslen}}%
%\par La liste des éléments à mélanger est :\par
\xdef\ListeDesCaracteresAUtiliser{}%
\xintFor* ##1 in{\xintSeq{1}{\ListeDesLettresUniqueslen}}\do{%
\xdef\ListeDesCaracteresAUtiliser{\ListeDesCaracteresAUtiliser \ListeDesLettresUniques[##1]/}%
}%
\xdef\ListeDesCaracteresAUtiliser{\ListeDesCaracteresAUtiliser \faa}%
\MelangeListeNew{\ListeDesCaracteresAUtiliser}{\NombreDeProduitATester}%
%Finalement, on utilise ces caractères :\par
\ignoreemptyitems%
\readlist*\ListeFinaleDesCaracteres{\faa}%
\restorecomparemode%
\reademptyitems%
}%
% \newcommand\DefiTable[2][]{%
\NewDocumentCommand\DefiTable{om}{%
% 1 les clés
% 2 la table de décodage
\useKVdefault[DefiTable]%
\setKV[DefiTable]{#1}%
\ifboolKV[DefiTable]{Creation}{%
\ifboolKV[DefiTable]{Graines}{\PfCGraineAlea{\useKV[DefiTable]{Graine}}}{}%
\DefiTableNombreLettreduCode{#2}%
\ifboolKV[DefiTable]{Restreint}{%
\xdef\PfCNbColonnes{\fpeval{\useKV[DefiTable]{ValeurMax}-\useKV[DefiTable]{ValeurMin}+1}}%
\begin{tabular}{|>{\columncolor{gray!15}}c|*{\PfCNbColonnes}{c|}}
\hline
\rowcolor{gray!15}$\times$&\xintFor* ##1 in {\xintSeq {1}{\PfCNbColonnes}}\do{%
\xintifForFirst{}{&}\fpeval{\useKV[DefiTable]{ValeurMin}+##1-1}%
}\\\hline%
\xintFor* ##1 in{\xintSeq{1}{10}}\do{%
##1\xintFor* ##2 in{\xintSeq{\useKV[DefiTable]{ValeurMin}}{\useKV[DefiTable]{ValeurMax}}}\do{%
&\xintFor* ##3 in{\xintSeq{1}{\NombreDeProduitATester}}\do{%
\xintifboolexpr{\fpeval{##1*##2}==\ListeDesProduits[##3] 'and' any(\useKV[DefiTable]{ValeurMin}<=##2<=\useKV[DefiTable]{ValeurMax},\useKV[DefiTable]{ValeurMin}<=##1<=\useKV[DefiTable]{ValeurMax})}{\ListeFinaleDesCaracteres[##3]}{}%
}%
}\\\hline%
}%
\end{tabular}%
}{%
\begin{tabular}{|>{\columncolor{gray!15}}c|*{10}{c|}}
\hline
\rowcolor{gray!15}$\times$&\xintFor* ##1 in {\xintSeq {1}{10}}\do{%
\xintifForFirst{}{&}##1%
}\\\hline%
\xintFor* ##1 in{\xintSeq{1}{10}}\do{%
##1\xintFor* ##2 in{\xintSeq{1}{10}}\do{%
&\xintFor* ##3 in{\xintSeq{1}{\NombreDeProduitATester}}\do{%
\xintifboolexpr{\fpeval{##1*##2}==\ListeDesProduits[##3] 'and' any(\useKV[DefiTable]{ValeurMin}<=##2<=\useKV[DefiTable]{ValeurMax},\useKV[DefiTable]{ValeurMin}<=##1<=\useKV[DefiTable]{ValeurMax})}{\ListeFinaleDesCaracteres[##3]}{}%
}%
}\\\hline%
}%
\end{tabular}%
}%
}{%
\setsepchar[*]{§* }%
\readlist*\ListeDefiTableCode{#2}%
\begin{NiceTabular}{>{\columncolor{gray!15}}{c}*{10}{c}}[hvlines,color-inside]
\rowcolor{gray!15}$\times$&\xintFor* ##1 in {\xintSeq {1}{10}}\do{%
\xintifForFirst{}{&}##1}
\\
1\xintFor* ##1 in {\xintSeq {1}{10}}\do{%
&\ListeDefiTableCode[1,##1]%
}\\
\xintFor* ##1 in {\xintSeq {2}{9}}\do{%
##1\xintFor* ##2 in {\xintSeq {1}{##1}}\do{%
&\ListeDefiTableCode[##2,\fpeval{##1-##2+1}]%
}\xintFor* ##2 in {\xintSeq {1}{\fpeval{10-##1}}}\do{%
&\ListeDefiTableCode[##1,\fpeval{##2+1}]%
}%
\\
}%
10&\ListeDefiTableCode[1,10]&\ListeDefiTableCode[2,9]&\ListeDefiTableCode[3,8]&\ListeDefiTableCode[4,7]&\ListeDefiTableCode[5,6]&\ListeDefiTableCode[6,5]&\ListeDefiTableCode[7,4]&\ListeDefiTableCode[8,3]&\ListeDefiTableCode[9,2]&\ListeDefiTableCode[10,1]\\
\end{NiceTabular}%
}%
}%
\NewDocumentCommand\DefiTableTexte{omm}{%
\useKVdefault[DefiTable]%
\setKV[DefiTable]{#1}%
\ifboolKV[DefiTable]{Creation}{%
\ifboolKV[DefiTable]{Graines}{\PfCGraineAlea{\useKV[DefiTable]{Graine}}}{}%
\DefiTableNombreLettreduCode{#3}%
\setsepchar[*]{\\* }%
\readlist*\ListeDefiTableTableau{#3}%
\xdef\ListeDefiTableMax{0}%
\xintFor* ##1 in{\xintSeq{1}{\ListeDefiTableTableaulen}}\do{%
\StrLen{\ListeDefiTableTableau[##1]}[\PfCDTLongueur]%
\xintifboolexpr{\ListeDefiTableMax<\PfCDTLongueur}{\xdef\ListeDefiTableMax{\fpeval{\PfCDTLongueur}}}{}%%
}%
%\par Le max est \ListeDefiTableMax
\begin{NiceTabular}{*{\fpeval{\ListeDefiTableMax}}{>{\centering\arraybackslash}m{\useKV[DefiTable]{LargeurT}}}}
\xintFor* ##1 in {\xintSeq {1}{\fpeval{\ListeDefiTableTableaulen}}}\do{%
\StrLen{\ListeDefiTableTableau[##1]}[\PfCDTLongueur]%
\xintFor* ##2 in {\xintSeq {1}{\PfCDTLongueur}}\do{%
\xintifForFirst{}{&}%
\StrMid{\ListeDefiTableTableau[##1]}{##2}{##2}[\DefiTableMaLettre]%
\IfStrEq{\DefiTableMaLettre}{ }{\Block[]{1-1}{}}{\Block[borders={bottom}]{1-1}{\ifboolKV[DefiTable]{Solution}{\StrMid{\ListeDefiTableTableau[##1]}{##2}{##2}}{}}}%
}\\
\StrLen{\ListeDefiTableTableau[##1]}[\PfCDTLongueur]%
\xintFor* ##2 in {\xintSeq {1}{\PfCDTLongueur}}\do{%
\xintifForFirst{}{&}%
\StrMid{\ListeDefiTableTableau[##1]}{##2}{##2}[\DefiTableMaLettre]%
\IfStrEq{\DefiTableMaLettre}{*}{}{%
\xintFor* ##3 in{\xintSeq{1}{\NombreDeProduitATester}}\do{%
\IfStrEq{\DefiTableMaLettre}{\ListeFinaleDesCaracteres[##3]}{\Block{}{\footnotesize\ListeDesProduits[##3]}}{}%
}%
}%
}\\
\StrLen{\ListeDefiTableTableau[##1]}[\PfCDTLongueur]%
\xintFor* ##2 in {\xintSeq {1}{\PfCDTLongueur}}\do{%
\xintifForFirst{}{&}
}\\
}%
\end{NiceTabular}%
}{%
\setsepchar[*]{§*/}%
\readlist*\ListeDefiTableTableau{#2}%
\xdef\ListeDefiTableMax{0}%
\setsepchar{§}%
\readlist*\ListeDefiTablePhrase{#3}%
\foreachitem\compteur\in\ListeDefiTableTableau{%
\xintifboolexpr{\ListeDefiTableMax<\listlen\ListeDefiTableTableau[\compteurcnt]}{\xdef\ListeDefiTableMax{\fpeval{\listlen\ListeDefiTableTableau[\compteurcnt]}}}{}%
}%
\begin{NiceTabular}{*{\fpeval{\ListeDefiTableMax}}{>{\centering\arraybackslash}m{\useKV[DefiTable]{LargeurT}}}}
\xintFor* ##1 in {\xintSeq {1}{\fpeval{\ListeDefiTableTableaulen}}}\do{%
\xintFor* ##2 in {\xintSeq {1}{\listlen\ListeDefiTableTableau[##1]}}\do{%
\xintifForFirst{}{&}\ifboolKV[DefiTable]{Solution}{%
\StrMid{\ListeDefiTablePhrase[##1]}{##2}{##2}[\DefiTableMaLettre]%
\IfStrEq{\DefiTableMaLettre}{*}{\Block[]{2-1}{}}{\Block[borders={bottom}]{2-1}{\StrMid{\ListeDefiTablePhrase[##1]}{##2}{##2}}}%
}{%
\IfStrEq{\ListeDefiTableTableau[##1,##2]}{*}{\Block[]{2-1}{}}{\Block[borders={bottom}]{2-1}{}}%
}%%
}\\
\xintFor* ##2 in {\xintSeq {1}{\listlen\ListeDefiTableTableau[##1]}}\do{%
\xintifForFirst{}{&}
}\\
\xintFor* ##2 in {\xintSeq {1}{\listlen\ListeDefiTableTableau[##1]}}\do{%
\xintifForFirst{}{&}\IfStrEq{\ListeDefiTableTableau[##1,##2]}{*}{}{\footnotesize\ifboolKV[DefiTable]{Math}{\ListeDefiTableTableau[##1,##2]}{\num{\ListeDefiTableTableau[##1,##2]}}}%
}\\
}%
\end{NiceTabular}%
}%
}%
|