summaryrefslogtreecommitdiff
path: root/macros/latex/contrib/profcollege/latex/PfCCompteBon.tex
blob: 1d5339b114c9105099f23d5b0f348e831ccd7704 (plain)
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
%%%
% Le compte est bon
%%%
\setKVdefault[CompteBon]{NombreCalculs=5,NombrePlaques=4,Solution=false,Relatifs=false,Original=false,Graines=false,Plaques=6,CDot=false}
\defKV[CompteBon]{Graine=\setKV[CompteBon]{Graines}}%

\makeatletter

\newcommand\PfC@CreerListeCalculs[4]{%
  \xdef\PfC@ListeCalculs{%
    #1+#2+#3+#4,%
    #1+#2+#3*#4/#1+#3*#4+#2/#3*#4+#1+#2,%
    #1+#3+#2*#4/#1+#2*#4+#3/#2*#4+#1+#3,%
    #1+#4+#2*#3/#1+#2*#3+#4/#2*#3+#1+#4,%
    #2+#3+#1*#4/#2+#1*#4+#3/#1*#4+#2+#3,%
    #2+#4+#1*#3/#2+#1*#3+#4/#2+#4+#1*#3,%
    #3+#4+#1*#2/#3+#1*#2+#4/#3+#4+#1*#2,%
    #1*#2+#3*#4/#3*#4+#1*#2,%
    #1*#3+#2*#4/#2*#4+#1*#3,%
    #1*#4+#2*#3/#2*#3+#1*#4,%
    #1*#2*#3+#4/#4+#1*#2*#3,
    #1*#2*#4+#3/#3+#1*#2*#4,%
    #1*#3*#4+#2/#2+#1*#3*#4,%
    #2*#3*#4+#1/#1+#2*#3*#4,%
    #1*#2*#3*#4,%
    #1+(#2+#3)*#4/(#2+#3)*#4+#1/#1+#4*(#2+#3)/#4*(#2+#3)+#1,%
    #1+(#2+#4)*#3/(#2+#4)*#3+#1/#1+#3*(#2+#4)/#3*(#2+#4)+#1,%
    #1+(#3+#4)*#2/(#3+#4)*#2+#1/#1+#2*(#3+#4)/#2*(#3+#4)+#1,%
    #2+(#1+#3)*#4,%
    #2+(#1+#4)*#3,%
    #2+(#3+#4)*#1,%
    #3+(#1+#2)*#4,%
    #3+(#1+#4)*#2,%
    #3+(#2+#4)*#1,%
    #4+(#1+#2)*#3,%
    #4+(#1+#3)*#2,%
    #4+(#2+#3)*#1,%
    (#1+#2+#3)*#4,%
    (#1+#2+#4)*#3,%
    (#1+#3+#4)*#2,%
    (#2+#3+#4)*#1,%
    (#1+#2)*(#3+#4),%
    (#1+#3)*(#2+#4),%
    (#1+#4)*(#2+#3)%
  }%
  \ifboolKV[CompteBon]{Relatifs}{%
    \xdef\PfC@ListeCalculs{%
      \PfC@ListeCalculs,%
      #1-#2-#3-#4,%
      #1-#2-#3*#4/#1-#3*#4-#2/#3*#4-#1-#2,%
      #1-#3-#2*#4/#1-#2*#4-#3/#2*#4-#1-#3,%
      #1-#4-#2*#3/#1-#2*#3-#4/#2*#3-#1-#4,%
      #2-#3-#1*#4/#2-#1*#4-#3/#1*#4-#2-#3,%
      #2-#4-#1*#3/#2-#1*#3-#4/#2-#4-#1*#3,%
      #3-#4-#1*#2/#3-#1*#2-#4/#3-#4-#1*#2,%
      #1*#2-#3*#4/#3*#4-#1*#2,%
      #1*#3-#2*#4/#2*#4-#1*#3,%
      #1*#4-#2*#3/#2*#3-#1*#4,%
      #1*#2*#3-#4/#4-#1*#2*#3,
      #1*#2*#4-#3/#3-#1*#2*#4,%
      #1*#3*#4-#2/#2-#1*#3*#4,%
      #2*#3*#4-#1/#1-#2*#3*#4,%
      #1*#2*#3*#4,%
      #1-(#2-#3)*#4/(#2-#3)*#4-#1/#1-#4*(#2-#3)/#4*(#2-#3)-#1,%
      #1-(#2-#4)*#3/(#2-#4)*#3-#1/#1-#3*(#2-#4)/#3*(#2-#4)-#1,%
      #1-(#3-#4)*#2/(#3-#4)*#2-#1/#1-#2*(#3-#4)/#2*(#3-#4)-#1,%
      #2-(#1-#3)*#4,%
      #2-(#1-#4)*#3,%
      #2-(#3-#4)*#1,%
      #3-(#1-#2)*#4,%
      #3-(#1-#4)*#2,%
      #3-(#2-#4)*#1,%
      #4-(#1-#2)*#3,%
      #4-(#1-#3)*#2,%
      #4-(#2-#3)*#1,%
      (#1-#2-#3)*#4,%
      (#1-#2-#4)*#3,%
      (#1-#3-#4)*#2,%
      (#2-#3-#4)*#1,%
      (#1-#2)*(#3-#4),%
      (#1-#3)*(#2-#4),%
      (#1-#4)*(#2-#3)%
    }%
  }{}%
}%

\newtoks\tokPfCCBRappels
\def\UpdatetoksCB#1\nil{\addtotok\tokPfCCBRappels{#1,}}%

\NewDocumentCommand\PfCCompteBonOriginal{o}{%
  \useKVdefault[CompteBon]
  \setKV[CompteBon]{#1}%
  %On définit la liste des cartes
  \xdef\PfCCBListeCartes{1,2,3,4,5,6,7,8,9,10,1,2,3,4,5,6,7,8,9,10,25,50,75,100}%
  \MelangeListe{\PfCCBListeCartes}{\useKV[CompteBon]{Plaques}}
  \readlist*\PfCCBListeTirage{\faa}
  \MelangeListe{\faa}{\useKV[CompteBon]{Plaques}}
  \readlist*\PfCCBListeTirageAffiche{\faa}
  %%Tirage ok
  \xdef\PfCCBResultatFinal{1001}%
  \whiledo{\PfCCBResultatFinal>1000}{%
    \xdef\PfCListeATrier{\PfCCBListeTirage[1]}%
    \xintFor* ##1 in{\xintSeq{2}{\useKV[CompteBon]{Plaques}}}\do{%
      \xdef\PfCListeATrier{\PfCListeATrier,\PfCCBListeTirage[##1]}%
    }%
    % 
    \tokPfCCBRappels{}%
    \xintFor* ##1 in{\xintSeq{1}{\fpeval{\useKV[CompteBon]{Plaques}-1}}}\do{%
      \MelangeListe{\PfCListeATrier}{2}
      \readlist*\PfCCBListeTirageIntermediaire{\faa}
      \xintifboolexpr{\PfCCBListeTirageIntermediaire[1]==1 || \PfCCBListeTirageIntermediaire[2]==1}{%
        % On ne fait pas de multiplication par 1
        \xdef\PfCCBAlea{\fpeval{randint(1,2)}}%
        \xintifboolexpr{\PfCCBAlea==1}{%
          \xdef\PfCCBTest{\PfCCBListeTirageIntermediaire[1]+\PfCCBListeTirageIntermediaire[2]=\fpeval{\PfCCBListeTirageIntermediaire[1]+\PfCCBListeTirageIntermediaire[2]}}%
          \expandafter\UpdatetoksCB\PfCCBTest\nil%
          \xdef\PfCCBResultat{\fpeval{\PfCCBListeTirageIntermediaire[1]+\PfCCBListeTirageIntermediaire[2]}}
          \xintifboolexpr{\PfCCBResultat>10000}{\xintBreakFor\xdef\PfCCBResultat{10000}}{}%
        }{%
          \xintifboolexpr{\PfCCBListeTirageIntermediaire[1]==\PfCCBListeTirageIntermediaire[2]}{%
            \xdef\PfCCBTest{\PfCCBListeTirageIntermediaire[1]+\PfCCBListeTirageIntermediaire[2]=\fpeval{\PfCCBListeTirageIntermediaire[1]+\PfCCBListeTirageIntermediaire[2]}}%
            \expandafter\UpdatetoksCB\PfCCBTest\nil%
            \xdef\PfCCBResultat{\fpeval{\PfCCBListeTirageIntermediaire[1]+\PfCCBListeTirageIntermediaire[2]}}
          }{%
            \xdef\PfCCBTest{\fpeval{max(\PfCCBListeTirageIntermediaire[1],\PfCCBListeTirageIntermediaire[2])}-\fpeval{min(\PfCCBListeTirageIntermediaire[1],\PfCCBListeTirageIntermediaire[2])}=\fpeval{max(\PfCCBListeTirageIntermediaire[1],\PfCCBListeTirageIntermediaire[2])-min(\PfCCBListeTirageIntermediaire[1],\PfCCBListeTirageIntermediaire[2])}}
            \expandafter\UpdatetoksCB\PfCCBTest\nil%
            \xdef\PfCCBResultat{\fpeval{abs(\PfCCBListeTirageIntermediaire[1]-\PfCCBListeTirageIntermediaire[2])}}
          }%
          \xintifboolexpr{\PfCCBResultat>10000}{\xintBreakFor\xdef\PfCCBResultat{10000}}{}%
        }%
        \xdef\PfCListeATrier{\fii,\PfCCBResultat}%
      }{%
        \xdef\PfCCBAlea{\fpeval{randint(1,3)}}%
        \xintifboolexpr{\PfCCBAlea==1}{%
          \xdef\PfCCBTest{\PfCCBListeTirageIntermediaire[1]+\PfCCBListeTirageIntermediaire[2]=\fpeval{\PfCCBListeTirageIntermediaire[1]+\PfCCBListeTirageIntermediaire[2]}}%
          \expandafter\UpdatetoksCB\PfCCBTest\nil%
          \xdef\PfCCBResultat{\fpeval{\PfCCBListeTirageIntermediaire[1]+\PfCCBListeTirageIntermediaire[2]}}
          \xintifboolexpr{\PfCCBResultat>10000}{\xintBreakFor\xdef\PfCCBResultat{10000}}{}%
        }{%
          \xintifboolexpr{\PfCCBAlea==2}{%
            \xintifboolexpr{\PfCCBListeTirageIntermediaire[1]==\PfCCBListeTirageIntermediaire[2]}{%
              \xdef\PfCCBTest{\PfCCBListeTirageIntermediaire[1]+\PfCCBListeTirageIntermediaire[2]=\fpeval{\PfCCBListeTirageIntermediaire[1]+\PfCCBListeTirageIntermediaire[2]}}%
              \expandafter\UpdatetoksCB\PfCCBTest\nil%
              \xdef\PfCCBResultat{\fpeval{\PfCCBListeTirageIntermediaire[1]+\PfCCBListeTirageIntermediaire[2]}}
            }{%
              \xdef\PfCCBTest{\fpeval{max(\PfCCBListeTirageIntermediaire[1],\PfCCBListeTirageIntermediaire[2])}-\fpeval{min(\PfCCBListeTirageIntermediaire[1],\PfCCBListeTirageIntermediaire[2])}=\fpeval{max(\PfCCBListeTirageIntermediaire[1],\PfCCBListeTirageIntermediaire[2])-min(\PfCCBListeTirageIntermediaire[1],\PfCCBListeTirageIntermediaire[2])}}
              \expandafter\UpdatetoksCB\PfCCBTest\nil%
              \xdef\PfCCBResultat{\fpeval{abs(\PfCCBListeTirageIntermediaire[1]-\PfCCBListeTirageIntermediaire[2])}}
            }%
            \xintifboolexpr{\PfCCBResultat>10000}{\xintBreakFor\xdef\PfCCBResultat{10000}}{}%
          }{%
            \xdef\PfCCBTest{\PfCCBListeTirageIntermediaire[1]*\PfCCBListeTirageIntermediaire[2]=\fpeval{\PfCCBListeTirageIntermediaire[1]*\PfCCBListeTirageIntermediaire[2]}}
            \expandafter\UpdatetoksCB\PfCCBTest\nil%
            \xdef\PfCCBResultat{\fpeval{\PfCCBListeTirageIntermediaire[1]*\PfCCBListeTirageIntermediaire[2]}}
            \xintifboolexpr{\PfCCBResultat>10000}{\xintBreakFor\xdef\PfCCBResultat{10000}}{}%
          }
        }%
        \xdef\PfCListeATrier{\fii,\PfCCBResultat}%
      }%
    }%
    \xintifboolexpr{\useKV[CompteBon]{Plaques}>5}{\xintifboolexpr{\PfCCBResultat<100}{\xdef\PfCCBResultat{1001}}{}}{}%
    \xdef\PfCCBResultatFinal{\PfCCBResultat}%
  }%
  \begin{center}
    \textbf{\PfCCBResultatFinal}
    
    \fbox{\PfCCBListeTirage[1]} \xintFor* ##1 in{\xintSeq{2}{\useKV[CompteBon]{Plaques}}}\do{\qquad \fbox{\PfCCBListeTirage[##1]}}%
  \end{center}
  \xdef\PfCCBListeRappels{\the\tokPfCCBRappels}%
  \setsepchar[*]{,*=}\ignoreemptyitems%
  \readlist*\PfCCBDecompositionEtapes{\PfCCBListeRappels}%
  \reademptyitems%
  \ifboolKV[CompteBon]{Solution}{%
    \begin{align*}
      \xintFor* ##1 in{\xintSeq{1}{\fpeval{\useKV[CompteBon]{Plaques}-1}}}\do{
      \StrSubstitute{\PfCCBDecompositionEtapes[##1,1]}{*}{\PfCSymbolTimes}[\PfCCBAffiche]\PfCCBAffiche&=\PfCCBDecompositionEtapes[##1,2]\xintifForLast{\\}{}
      }%
    \end{align*}
  }{}%
}%

\NewDocumentCommand\CompteBon{o}{%
  \useKVdefault[CompteBon]%
  \setKV[CompteBon]{#1}%
  \ifboolKV[CompteBon]{Graines}{\PfCGraineAlea{\useKV[CompteBon]{Graine}}}{}%
  \ifboolKV[CompteBon]{Original}{%
    \PfCCompteBonOriginal[#1]%
  }{%
    % on choisit NombrePlaques parmi la liste des nombres 1 à 9, 10/25/50/75/100, La moitié +1 devant appartenir à 1..9
    \xdef\PfCCBListeEntiers{2,3,4,5,6,7,8,9}%
    \xdef\PfCCBListeMultiples{10,25,50,75,100}%
    \xdef\PfCCBNbPlaqueEntiers{\fpeval{floor(\useKV[CompteBon]{NombrePlaques}/2)+1}}%
    \xdef\PfCCBNbPlaqueMultiples{\useKV[CompteBon]{NombrePlaques}-\PfCCBNbPlaqueEntiers}%
    \MelangeListe{\PfCCBListeEntiers}{\PfCCBNbPlaqueEntiers}%
    \setsepchar{,}%
    \ignoreemptyitems%
    \readlist*\PfCCBListeEntiersChoisis{\faa}%
    \MelangeListe{\PfCCBListeMultiples}{\PfCCBNbPlaqueMultiples}%
    \ignoreemptyitems%
    \readlist*\PfCCBListeMultiplesChoisis{\faa}%
    \reademptyitems%
    \xdef\PfCCBListeToutesCartes{}%
    \foreachitem\compteur\in\PfCCBListeEntiersChoisis{%
      \xdef\PfCCBListeToutesCartes{\PfCCBListeToutesCartes{},\PfCCBListeEntiersChoisis[\compteurcnt]}%
    }%
    \foreachitem\compteur\in\PfCCBListeMultiplesChoisis{%
      \xdef\PfCCBListeToutesCartes{\PfCCBListeToutesCartes{},\PfCCBListeMultiplesChoisis[\compteurcnt]}%
    }%
    \MelangeListe{\PfCCBListeToutesCartes}{4}%
    \readlist*\PfCCBListeFinaleCartes{\faa}%
    % Choix des calculs
    \xdef\PfC@CalculUn{\PfCCBListeFinaleCartes[1]}%
    \xdef\PfC@CalculDeux{\PfCCBListeFinaleCartes[2]}%
    \xdef\PfC@CalculTrois{\PfCCBListeFinaleCartes[3]}%
    \xdef\PfC@CalculQuatre{\PfCCBListeFinaleCartes[4]}%
    \PfC@CreerListeCalculs{\PfC@CalculUn}{\PfC@CalculDeux}{\PfC@CalculTrois}{\PfC@CalculQuatre}
    \MelangeListe{\PfC@ListeCalculs}{\useKV[CompteBon]{NombreCalculs}}%
    \setsepchar[*]{,*/}%
    \readlist*\PfC@ListeCalculsChoisis{\faa}%
    \begin{center}
      \setlength{\tabcolsep}{0.5\tabcolsep}
      % Le tableau des nombres
      \begin{NiceTabular}{m{20pt}m{10pt}m{20pt}m{10pt}m{20pt}m{10pt}m{20pt}}
        \Block[draw]{}{\PfCCBListeFinaleCartes[1]}&&\Block[draw]{}{\PfCCBListeFinaleCartes[2]}&&\Block[draw]{}{\PfCCBListeFinaleCartes[3]}&&\Block[draw]{}{\PfCCBListeFinaleCartes[4]}
      \end{NiceTabular}
      
      \bigskip
      
      % Le tableau des calculs%
      \begin{NiceTabular}{m{30pt}cccm{20pt}m{10pt}m{20pt}m{10pt}m{20pt}m{10pt}m{20pt}}
        \xintFor* ##1 in{\xintSeq{1}{\useKV[CompteBon]{NombreCalculs}}}\do{%
          \Block[draw]{}{\num{\fpeval{\PfC@ListeCalculsChoisis[##1,1]}}}&&$=$&&\Block[draw]{}{~}&\Block{}{~}&\Block[draw]{}{~}&\Block{}{~}&\Block[draw]{}{~}&\Block{}{~}&\Block[draw]{}{~}\\
          \ifboolKV[CompteBon]{Solution}{\Block{1-11}{\footnotesize Une solution : \StrSubstitute[0]{\PfC@ListeCalculsChoisis[##1,1]}{*}{\PfCSymbolTimes}[\PfCEcritureCalcul]$\PfCEcritureCalcul$}}{}\\
        }%
      \end{NiceTabular}
    \end{center}
  }%
}%

\makeatother