%%AMC:preprocess_command=./prePythonTex4AMC
%%AMC:jobspecific=1
%%AMC:latex_engine=pdflatex --shell-escape

% Compilation Texmaker : Utilisateur/Commandes utilisateur
%--------------------------
% Shell Python :
% pdflatex --shell-escape -synctex=1 -interaction=nonstopmode %.tex|
% python /usr/share/texlive/texmf-dist/scripts/pythontex/pythontex.py %.tex|
% pdflatex --shell-escape -synctex=1 -interaction=nonstopmode %.tex|
%------------------------
% Copier-coller la ligne ci-dessous dans Utilisateur/Commandes Utilisateur/Editer Commandes Utilisateur
%------------------------
% pdflatex --shell-escape -synctex=1 -interaction=nonstopmode %.tex | python /usr/share/texlive/texmf-dist/scripts/pythontex/pythontex.py %.tex | pdflatex --shell-escape -synctex=1 -interaction=nonstopmode %.tex
%--------------------------

\documentclass[a4paper]{article}
\RequirePackage{etex}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage[french]{babel}
\selectlanguage{french}
\usepackage[francais,bloc,completemulti]{automultiplechoice}
\usepackage{fancyhdr,amssymb,amsmath}
\usepackage{multicol}
\usepackage[babel=true,kerning=true]{microtype}
\usepackage{graphicx}
\usepackage{float}
\usepackage{wrapfig}
\usepackage{pgfplots}
\usepackage{wrapfig}
\usepackage{tikz}
\usetikzlibrary{arrows,automata}
\usepackage{minted}
\usepackage{verbatimbox}

\pgfplotsset{compat = newest}

% ---------- Utilisation de codes Python -----
\usepackage{pythontex}
\usepackage{csvsimple}

%----------------------------------------------


\makeatletter
\renewcommand{\explain}[1]{ %
    \ifAMC@correc%
    \AMCif@env{question}{\par\noindent{\AMC@loc@explain#1}}{\AMC@error@explain}\vspace{1ex}%
    \else%
    \AMCif@env{question}{}{\AMC@error@explain}%
    \fi%
}
\makeatother

\def\AMCbeginQuestion#1#2{\par\noindent{\bf Q#1} #2\hspace*{1em}}


\begin{pycode}
import numpy as np
import math
from fractions import Fraction as F
from sympy import *
#from numpy.random import default_rng
rng=np.random.default_rng(12345)
import  string

#np.random.seed(12345)
# IMPORTANT : Graine pour la fonction random

from math import *
from turtle import *
import matplotlib.pyplot as plt


def createLF(size):
    LF=[]
    i=0
    while i < size-1:
        comp=rng.integers(0,high=2,size=1)[0]
        if comp == 0:
            LF.append("NORM")
        else:
            LF.append("COMP")
        LF.append(string.ascii_uppercase[i])
        operator=rng.integers(0,high=2,size=1)[0]
        if operator == 0:
            LF.append("SUM")
        else:
            LF.append("PROD")
        i+=1
    comp=rng.integers(0,high=2,size=1)[0]
    if comp == 0:
        LF.append("NORM")
    else:
        LF.append("COMP")
    LF.append(string.ascii_uppercase[i])
    return LF

def printLF(LF):
    toprint=""
    i=0
    while i < len(LF):
        #test if i is NORM or COMP
        if math.fmod(i,3) == 0:
            i+=1
            if LF[i-1] == "COMP":
                toprint=toprint+LF[i]+"'"
            else:
                toprint=toprint+LF[i]
        else:
            if LF[i] == "SUM":
                toprint=toprint+"+"
            else:
                toprint=toprint+"."
        i+=1
    return toprint

def printLet(vars):
    print("Let ")
    i=0
    while i < len(vars)-1:
        print(string.ascii_uppercase[i]+" = "+str(vars[i])+", ")
        i+=1
    print(string.ascii_uppercase[i]+" = "+str(vars[i])+".")
    
    
        
#Let A = \py{A} and B = \py{B}\\


\end{pycode}



\newcommand{\sujet}{%
\exemplaire{1}{%
%\shorthandon{;}
%%% debut de l’en-tête des copies :
\AMCassociation{\id}

\begin{minipage}{.4\linewidth}
\centering\large\bf Test\\ Date
\end{minipage}
\champnom{\fbox{\begin{minipage}{.5\linewidth}

\centering\textsc{\nom{} \prenom{}}
%\vspace*{.5cm}\dotfill
\vspace*{2mm}
\end{minipage}}}

%%% fin de l’en-tête

\begin{center}
\hrule\vspace{2mm}
\bf\Large Logical Functions
\vspace{1mm}\hrule
\end{center}
\restituegroupe{logicfunc}

\clearpage

}%fin commande \exemplaire
}%fin commande \newcommand
%--------
% DOCUMENT
%--------
\begin{document}

\setdefaultgroupmode{withreplacement}


\element{logicfunc}{
\begin{question}{logicf1}\bareme{mz=3}
\pyc{nbvars=rng.integers(2,high=6,size=1)[0]}
\pyc{vars=rng.integers(0,high=2,size=nbvars)}

%\pyc{B=rng.integers(0,high=1,size=1)[0]}
\pyc{printLet(vars)}

\pyc{LF=createLF(nbvars)}
%\pyc{answers1=answers(LF,A,B)}
Let F = \py{printLF(LF)} \\
What's the correct value of F ?
    \begin{reponseshoriz}
        \bonne{F= ok}
        \mauvaise{F = ko}
    \end{reponseshoriz}
\end{question}
}

\setgroupmode{logicfunc}{fixed}



\csvreader[head to column names]{../liste.csv}{}{\sujet}

\end{document}

