\documentclass[12pt]{article}
\usepackage{ammaths}
\usealgorithms

\begin{document}

\module{Algorithms}{1}{01}{1 period}

%\prereq{}

\object{\begin{itemize}
	\item Read an algorithm.
	\item Follow an algorithm with paper and pen.
	\end{itemize}}

\mater{\begin{itemize}
	\item Slideshow explaining the main concepts. 
	\item Task sheet.
	\item Answer sheet.
\end{itemize}}

\modpart{Short lecture about algorithm}{10 mins}

Using a slideshow, the teacher explains the main concepts about algorithms and gives an example.

\modpart{Group work}{45 mins}

The class is divided in four groups. Each group has to carry out a few tasks involving algorithms. Each task is
awarded a certain mark to make up a final mark at the end of the lesson.


\pagebreak

\moddocdis{Algorithms}{1}{01}{Task sheet}

%config des mots dans algorithme
\SetKwIF{If}{ElseIf}{Else}{If}{then}{else if}{else}{end\_if}
\SetKwFor{For}{For}{do}{end\_for}
\SetKwBlock{Begin}{Begin}{end}


\sectionblack{Algorithm \# 1}

\begin{minipage}{5.5cm}
\incmargin{1em}
\begin{algorithm}[H]
  %\KwData{$x$, real number}
  \Begin{\KwIn{$A$}
  $A+2\rightarrow A$ \;
  \KwOut{$A$}}
\end{algorithm}
\decmargin{1em}
\end{minipage}
\begin{minipage}{10cm}
\begin{enumerate}
\item Apply this algorithm to the following inputs.
\begin{center}
\begin{tabular}{|>\hfil p{2cm}|*{4}{>\hfil p{0.6cm}|}}
\hline
Input & $0$ & $5$ & $-2$ & $10$\\\hline
Output &  &  &  & \\ \hline
\end{tabular}
\end{center}
\item What seems to be the purpose of this algorithm ?
\begin{center}
\begin{tabular}{|p{8cm}|}
\hline
\rule{0pt}{1.5cm} \\ \hline
\end{tabular}
\end{center}
\end{enumerate}
\end{minipage}


\sectionblack{Algorithm \# 2}

\begin{minipage}{5.5cm}
\incmargin{1em}
\begin{algorithm}[H]
  %\KwData{$x$, real number}
	\Begin{  \KwIn{$x$\;}
\eIf{$x>0$}{\KwOut{$x$}}{\KwOut{$-x$}}
    }
\end{algorithm}
\decmargin{1em}
\end{minipage}
\begin{minipage}{10cm}
\begin{enumerate}
\item Apply this algorithm to the following inputs.
\begin{center}
\begin{tabular}{|>\hfil p{2cm}|*{6}{>\hfil p{0.56cm}|}}
\hline
Input & $2$ & $-2$ & $5$ & $-5$ & $-8$ & $-9$ \\\hline
Output &  &  &  & & &\\ \hline
\end{tabular}
\end{center}
\item What seems to be the purpose of this algorithm ?
\begin{center}
\begin{tabular}{|p{8cm}|}
\hline
\rule{0pt}{1.5cm} \\ \hline
\end{tabular}
\end{center}
\end{enumerate}
\end{minipage}


\sectionblack{Algorithm \# 3}


\begin{minipage}{5.5cm}
\incmargin{1em}
\begin{algorithm}[H]
%\caption{ }
%\KwData{$x$ and $y$, integers}
\Begin{\KwIn{$(x,y)$}
$10x+y\rightarrow u$ \;
$100u\rightarrow v$ \;
$100v\rightarrow w$ \;
$u+v+w\rightarrow s$ \;
\KwOut{$s$}}
\end{algorithm}
\decmargin{1em}
\end{minipage}
\begin{minipage}{10cm}
Apply this algorithm to the following inputs.
\begin{center}
\begin{tabular}{|>\hfil p{2cm}|*{3}{>\hfil p{1cm}|}}
\hline
Input & $(5,3)$ & $(2,1)$ & $(6,7)$\\\hline
Output &  &  &  \\ \hline
\end{tabular}
\end{center}
\end{minipage}

\pagebreak

\sectionblack{Algorithm \# 4}

\begin{minipage}{5.5cm}
\incmargin{1em}
\begin{algorithm}[H]
%\caption{ }
%\KwData{$A$ and $B$, real numbers}
\Begin{\KwIn{$(A,B)$}
$A+B\rightarrow A$ \;
$A-B\rightarrow B$ \;
$A-B\rightarrow A$ \;
\KwOut{$(A,B)$}}
\end{algorithm}
\decmargin{1em}
\end{minipage}
\begin{minipage}{10cm}
\begin{enumerate}
\item Apply this algorithm to the following inputs.
\begin{center}
\begin{tabular}{|>\hfil p{2cm}|*{3}{c|}}
\hline
Input & $(2,3)$ & $(5451,721)$ & $(\sqrt{5},\pi)$\\\hline
Output &  &  &  \\ \hline
\end{tabular}
\end{center}
\item What seems to be the purpose of this algorithm ?
\begin{center}
\begin{tabular}{|p{8cm}|}
\hline
\rule{0pt}{1.5cm} \\ \hline
\end{tabular}
\end{center}
\end{enumerate}
\end{minipage}

\sectionblack{Algorithm \# 5}


\begin{minipage}{7.5cm}
\incmargin{1em}
\begin{algorithm}[H]
%\KwData{$u$, real number and $i$, integer}
\Begin{\KwIn{$u$}
$1\rightarrow$ Step \;
\KwOut{``Step 1 : '', $u$}
      % ci-dessous pour faire bloc repeat batard
      \SetKwBlock{Begin}{Repeat}{end\_repeat}
     \Begin(9 times)
     {Step +1 $\rightarrow$ Step \;
     \eIf{$u$ \emph{is even}\\}{$\frac{u}{2}\rightarrow u$}{$3\times u+1\rightarrow u$}
     \KwOut{``Step '', Step ,`` : '', $u$}
      % ci-dessous pour retourner � utilisation normale
      \SetKwBlock{Begin}{Repeat}{end}
}}
\end{algorithm}
\decmargin{1em}
\end{minipage}
\begin{minipage}{8cm}
Apply this algorithm to the following inputs.
\begin{center}
\begin{tabular}{|>\hfil p{2cm}|*{2}{>\hfil p{2cm}|}}
\hline
Input & $1$ & $6$ \\\hline
Output 1 &  &  \\ \hline
Output 2 &  &  \\ \hline
Output 3 &  &  \\ \hline
Output 4 &  &  \\ \hline
Output 5 &  &  \\ \hline
Output 6 &  &  \\ \hline
Output 7 &  &  \\ \hline
Output 8 &  &  \\ \hline
Output 9 &  &  \\ \hline
Output 10 &  &  \\ \hline
\end{tabular}
\end{center}
\end{minipage}


\sectionblack{Extras}
\begin{enumerate}
\item In a shop, during sale time, there is a 10\% discount if the amount of the purchase is greater than or equal to
$500$ pounds. Write an aglorithm that computes actual amount paid by the customer.
\begin{center}
\begin{minipage}{14cm}
\incmargin{1em}
\begin{algorithm}[H]
%\KwData{$n$, $i$ and $t$, three integers}
\Begin{
\vspace{2cm}}
\end{algorithm}
\decmargin{1em}
\end{minipage}
\end{center}
\item Write an algorithm that builds the multiplication table for a number less than 10.
\begin{center}
\begin{minipage}{14cm}
\incmargin{1em}
\begin{algorithm}[H]
%\KwData{$n$, $i$ and $t$, three integers}
\Begin{
\vspace{2cm}}
\end{algorithm}
\decmargin{1em}
\end{minipage}
\end{center}\end{enumerate}

% \sectionblack{Algorithm \# 6}
% \begin{center}
% \begin{minipage}{14cm}
% \incmargin{1em}
% \begin{algorithm}[H]
% %\KwData{$n$, $i$ and $t$, three integers}
% \Begin{
% $1 \rightarrow n$ \;
% $101 \rightarrow i$ \;
% $alea(100) \rightarrow t$ \;
% \While{$i \neq t$}{
% 	\KwIn{$i$}
% 	\Switch{value of $i$}{
% 		\uCase{$i=t$}{\KwOut{``You won after the'' $n$``th attempt. Congratulations !'' }}
% 		\uCase{$i<t$}{\KwOut{$i$ ``is too small. Try again.'' \; $n+1 \rightarrow n$ \;}}
% 		\uCase{$i>t$}{\KwOut{$i$ ``is too big. Try again.'' \; $n+1 \rightarrow n$ \;}}
% 	}
% }}
% \end{algorithm}
% \decmargin{1em}
% \end{minipage}\end{center}
% \begin{enumerate}
% \item What seems to be the purpose of this algorithm ?
% \item \begin{enumerate}
% 	\item What is the use of the number $n$ ?
% 	\item What is the initial value of $n$ ? Could we use another one ?
% 	\end{enumerate}
% \item \begin{enumerate}
% 	\item What is the use of the number $i$ ?
% 	\item What is the initial value of $i$ ? Could we use another one ?
% 	\end{enumerate}
% \item Change the algorithm to add a way to control if the input is between $1$ and $100$.
% \end{enumerate}


\end{document}
