summaryrefslogtreecommitdiff
path: root/macros/latex/contrib/profcollege/latex/PfCCryptarithme.tex
blob: bfa2e8c76afdef88f80f8e23c55e73cde133f30c (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
%%%
% Cryptarithmes
%%%
\setKVdefault[Crypta]{Solution=false,ListeLettres={A,B,C,D,E,F,G,H,I,J},Tableau=false}%
\defKV[Crypta]{Indices=\setKV[Crypta]{Tableau}}%

\colorlet{PfCCouleurVirgule}{black}

\NewDocumentCommand\PfCRemplaceLettre{m}{%
  \IfStrEqCase{#1}{%
    {0}{\PfCCryptaListe[1]}%
    {1}{\PfCCryptaListe[2]}%
    {2}{\PfCCryptaListe[3]}%
    {3}{\PfCCryptaListe[4]}%
    {4}{\PfCCryptaListe[5]}%
    {5}{\PfCCryptaListe[6]}%
    {6}{\PfCCryptaListe[7]}%
    {7}{\PfCCryptaListe[8]}%
    {8}{\PfCCryptaListe[9]}%
    {9}{\PfCCryptaListe[10]}%
  }%
}%

\NewDocumentCommand\PfCchiffrecrypta{m}{%
  \ifboolKV[Crypta]{Solution}{#1}{\PfCRemplaceLettre{#1}}%
}%

\NewDocumentCommand\PfCCryptaTestIndice{m}{%
  \xintFor* ##1 in{\xintSeq{1}{\PfCCryptaListeIndicelen}}\do{%
    \xintifboolexpr{\PfCCryptaListeIndice[##1]==#1}{\PfCRemplaceLettre{#1}\xintBreakFor}{}%
  }%
}%

\NewDocumentCommand\BuildCryptaTab{}{%
  \xdef\PfCFooCryptaIndices{\useKV[Crypta]{Indices}}%
  \setsepchar{,}%
  \readlist*\PfCCryptaListeIndice{\PfCFooCryptaIndices}%
  \begin{tabular}{|*{10}{c|}}
    \hline
    0&1&2&3&4&5&6&7&8&9\\
    \hline
    \PfCCryptaTestIndice{0}&\PfCCryptaTestIndice{1}&\PfCCryptaTestIndice{2}&\PfCCryptaTestIndice{3}&\PfCCryptaTestIndice{4}&\PfCCryptaTestIndice{5}&\PfCCryptaTestIndice{6}&\PfCCryptaTestIndice{7}&\PfCCryptaTestIndice{8}&\PfCCryptaTestIndice{9}\\%
    \hline
  \end{tabular}
}%

\NewDocumentCommand\CryptarithmeAdd{omm}{%
  \useKVdefault[Crypta]%
  \setKV[Crypta]{#1}%
  \xdef\PfCFooCryptaListe{\useKV[Crypta]{ListeLettres}}%
  \setsepchar{,}%
  \readlist*\PfCCryptaListe{\PfCFooCryptaListe}%
  \ifboolKV[Crypta]{Solution}{\opset{carryadd}}{\opset{carryadd=false}}%
  \begingroup
  \setlength{\baselineskip}{1.75em}
  \opset{lineheight=\baselineskip} % nécessaire
  \opadd[decimalsepsymbol={,},lineheight=1.75em,columnwidth=1.5em,voperator=bottom,operandstyle=\PfCchiffrecrypta,resultstyle=\PfCchiffrecrypta,operandstyle.1.d=\color{PfCCouleurVirgule},operandstyle.2.d=\color{PfCCouleurVirgule},resultstyle.d=\color{PfCCouleurVirgule}]{#2}{#3}%
  \endgroup
  \ifboolKV[Crypta]{Tableau}{\\\BuildCryptaTab}{}%
}%

\NewDocumentCommand\CryptarithmeMAdd{om}{%
  \useKVdefault[Crypta]%
  \setKV[Crypta]{#1}%
  \xdef\PfCFooCryptaListe{\useKV[Crypta]{ListeLettres}}%
  \setsepchar{,}%
  \readlist*\PfCCryptaListe{\PfCFooCryptaListe}%
  \ifboolKV[Crypta]{Solution}{\opset{carryadd}}{\opset{carryadd=false}}%
  \opmanyadd[decimalsepsymbol={,},lineheight=1.75em,columnwidth=1.5em,vmanyoperator=bottom,operandstyle=\PfCchiffrecrypta,resultstyle=\PfCchiffrecrypta,resultstyle.d=\color{PfCCouleurVirgule}]#2%
  \ifboolKV[Crypta]{Tableau}{\\\BuildCryptaTab}{}%
}%

\NewDocumentCommand\CryptarithmeSous{omm}{%
  \useKVdefault[Crypta]%
  \setKV[Crypta]{#1}%
  \xdef\PfCFooCryptaListe{\useKV[Crypta]{ListeLettres}}%
  \setsepchar{,}%
  \readlist*\PfCCryptaListe{\PfCFooCryptaListe}%
  \ifboolKV[Crypta]{Solution}{\opset{carrysub}}{\opset{carrysub=false}}%
   \begingroup
   \setlength{\baselineskip}{1.75em}
   \opset{lineheight=\baselineskip} % nécessaire
   \opsub[decimalsepsymbol={,},lineheight=1.75em,columnwidth=1.5em,voperator=bottom,operandstyle=\PfCchiffrecrypta,resultstyle=\PfCchiffrecrypta,operandstyle.1.d=\color{PfCCouleurVirgule},operandstyle.2.d=\color{PfCCouleurVirgule},resultstyle.d=\color{PfCCouleurVirgule}]{#2}{#3}%
   \endgroup
   \ifboolKV[Crypta]{Tableau}{\\\BuildCryptaTab}{}%
}%

\NewDocumentCommand\CryptarithmeMul{omm}{%
  \useKVdefault[Crypta]%
  \setKV[Crypta]{#1}%
  \xdef\PfCFooCryptaListe{\useKV[Crypta]{ListeLettres}}%
  \setsepchar{,}%
  \readlist*\PfCCryptaListe{\PfCFooCryptaListe}%
  \begingroup
  \setlength{\baselineskip}{1.75em}
  \opset{lineheight=\baselineskip} % nécessaire
  \opmul[decimalsepsymbol={,},lineheight=1.75em,columnwidth=1.5em,voperator=bottom,operandstyle=\PfCchiffrecrypta,intermediarystyle=\PfCchiffrecrypta,resultstyle=\PfCchiffrecrypta,operandstyle.1.d=\color{PfCCouleurVirgule},operandstyle.2.d=\color{PfCCouleurVirgule},resultstyle.d=\color{PfCCouleurVirgule}]{#2}{#3}%
  \endgroup
  \ifboolKV[Crypta]{Tableau}{\\\BuildCryptaTab}{}%
}%

\NewDocumentCommand\CryptarithmeDiv{omm}{%
  \useKVdefault[Crypta]%
  \setKV[Crypta]{#1}%
  \xdef\PfCFooCryptaListe{\useKV[Crypta]{ListeLettres}}%
  \setsepchar{,}%
  \readlist*\PfCCryptaListe{\PfCFooCryptaListe}%
  \opidiv[decimalsepsymbol={,},lineheight=1.75em,columnwidth=1.5em,voperator=bottom,displayintermediary=all,operandstyle=\PfCchiffrecrypta,intermediarystyle=\PfCchiffrecrypta,remainderstyle=\PfCchiffrecrypta,resultstyle=\PfCchiffrecrypta,operandstyle.1.d=\color{PfCCouleurVirgule},operandstyle.2.d=\color{PfCCouleurVirgule},resultstyle.d=\color{PfCCouleurVirgule}]{#2}{#3}%
  \ifboolKV[Crypta]{Tableau}{\\\BuildCryptaTab}{}%
}%