cws/cw05.tex
changeset 268 e43f7e92ba26
parent 251 3dd550b9b0e3
child 278 0c2481cd8b1c
equal deleted inserted replaced
267:9e0216756771 268:e43f7e92ba26
    25 \noindent
    25 \noindent
    26 Also note that the running time of each part will be restricted to a
    26 Also note that the running time of each part will be restricted to a
    27 maximum of 30 seconds on my laptop.
    27 maximum of 30 seconds on my laptop.
    28 
    28 
    29 \DISCLAIMER{}
    29 \DISCLAIMER{}
       
    30 \newpage
    30 
    31 
    31 \subsection*{Reference Implementation}
    32 \subsection*{Reference Implementation}
    32 
    33 
    33 As usual, this Scala assignment comes with a reference implementation in form of
    34 As usual, this Scala assignment comes with a reference implementation in
    34 two \texttt{jar}-files. You can download them from KEATS. They allow you to run any
    35 form of two \texttt{jar}-files. You can download them from KEATS. They
    35 test cases on your own computer. For example you can call Scala on the command line with the
    36 allow you to run any test cases on your own computer. For example you
    36 option \texttt{-cp bf.jar} and then query any function from the
    37 can call Scala on the command line with the option \texttt{-cp bf.jar}
    37 \texttt{bf.scala} template file. You have to
    38 and then query any function from the \texttt{bf.scala} template file.
    38 prefix the calls with \texttt{CW10a} and \texttt{CW10b}, respectively. For example
    39 You have to prefix the calls with \texttt{CW10a} and \texttt{CW10b},
       
    40 respectively. For example
    39 
    41 
    40 
    42 
    41 \begin{lstlisting}[language={},xleftmargin=1mm,numbers=none,basicstyle=\ttfamily\small]
    43 \begin{lstlisting}[language={},xleftmargin=1mm,numbers=none,basicstyle=\ttfamily\small]
    42 $ scala -cp bf.jar
    44 $ scala -cp bf.jar
    43 scala> import CW10a._  
    45 scala> import CW10a._  
    74   * *     * *     * *     * *     * *     * *     * *     * *
    76   * *     * *     * *     * *     * *     * *     * *     * *
    75  *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *
    77  *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *
    76 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
    78 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
    77 \end{lstlisting}%$
    79 \end{lstlisting}%$
    78 
    80 
    79 
    81 \newpage
    80 
    82 
    81 \subsection*{Part 1 (6 Marks)}
    83 \subsection*{Part 1 (6 Marks)}
    82 
    84 
    83 Coming from Java or C++, you might think Scala is a rather esoteric
    85 Coming from Java or C++, you might think Scala is a rather esoteric
    84 programming language.  But remember, some serious companies have built
    86 programming language.  But remember, some serious companies have built
   104 I am not sure whether this is just an elaborate April fools' joke---judge
   106 I am not sure whether this is just an elaborate April fools' joke---judge
   105 yourself:
   107 yourself:
   106 
   108 
   107 \begin{center}
   109 \begin{center}
   108 \url{https://www.microsoft.com/en-us/p/brainf-ck/9nblgggzhvq5}
   110 \url{https://www.microsoft.com/en-us/p/brainf-ck/9nblgggzhvq5}
   109 \end{center}  
   111 \end{center}  \bigskip
   110 
   112 
   111 
   113 
   112 \noindent
   114 \noindent
   113 As mentioned above, brainf*** has 8 single-character commands, namely
   115 As mentioned above, brainf*** has 8 single-character commands, namely
   114 \texttt{'>'}, \texttt{'<'}, \texttt{'+'}, \texttt{'-'}, \texttt{'.'},
   116 \texttt{'>'}, \texttt{'<'}, \texttt{'+'}, \texttt{'-'}, \texttt{'.'},
   153   \texttt{Map()}, that is nothing is stored in the
   155   \texttt{Map()}, that is nothing is stored in the
   154   memory; \texttt{Map(0 -> 1, 2 -> 3)} stores \texttt{1} at
   156   memory; \texttt{Map(0 -> 1, 2 -> 3)} stores \texttt{1} at
   155   memory location \texttt{0}, and at \texttt{2} it stores \texttt{3}. The
   157   memory location \texttt{0}, and at \texttt{2} it stores \texttt{3}. The
   156   convention is that if we query the memory at a location that is
   158   convention is that if we query the memory at a location that is
   157   \emph{not} defined in the \texttt{Map}, we return \texttt{0}. Write
   159   \emph{not} defined in the \texttt{Map}, we return \texttt{0}. Write
   158   a function, \texttt{sread}, that takes a memory (a \texttt{Map}) and
   160   a `safe-read' function, \texttt{sread}, that takes a memory (a \texttt{Map}) and
   159   a memory pointer (an \texttt{Int}) as arguments, and `safely' reads the
   161   a memory pointer (an \texttt{Int}) as arguments, and `safely' reads the
   160   corresponding memory location. If the \texttt{Map} is not defined at
   162   corresponding memory location. If the \texttt{Map} is not defined at
   161   the memory pointer, \texttt{sread} returns \texttt{0}.
   163   the memory pointer, \texttt{sread} returns \texttt{0}.
   162 
   164 
   163   Write another function \texttt{write}, which takes a memory, a
   165   Write another function \texttt{write}, which takes a memory, a
   323   \caption{The rules for how commands in the brainf*** language update the program counter \texttt{pc},
   325   \caption{The rules for how commands in the brainf*** language update the program counter \texttt{pc},
   324     the memory pointer \texttt{mp} and the memory \texttt{mem}.\label{comms}}
   326     the memory pointer \texttt{mp} and the memory \texttt{mem}.\label{comms}}
   325   \end{figure}
   327   \end{figure}
   326 \end{itemize}\bigskip  
   328 \end{itemize}\bigskip  
   327 
   329 
   328 \newpage
   330 %%\newpage
   329 
   331 
   330 \subsection*{Part 2 (4 Marks)}
   332 \subsection*{Part 2 (4 Marks)}
   331 
   333 
   332 I am sure you agree while it is fun to look at bf-programs, like the
   334 I am sure you agree while it is fun to look at bf-programs, like the
   333 Sierpinski triangle or the Mandelbrot program, being interpreted, it
   335 Sierpinski triangle or the Mandelbrot program, being interpreted, it