summaryrefslogtreecommitdiff
path: root/ss2016/algodat/01/H1-1.md
blob: d93f86c8a604f357ee93c81dbb18edcd2c672392 (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
a)

\begin{algorithmic}[1]
  \FORALL{entries $e$ on the shopping list}
    \STATE{$c \leftarrow \text{category of $e$}$}
    \STATE{Go to shelf $s$ labeled $c$}
    \FORALL{products $p$ on $s$} \label{alg:loopstart}
      \IF{$p$ matches $e$} 
        \STATE{add $p$ to shopping basket}
        \STATE{break out of loop started in line \ref{alg:loopstart}}
      \ENDIF
    \ENDFOR
  \ENDFOR
\end{algorithmic}

b)

\begin{algorithmic}[1]
  \WHILE{not at destination within forest}
    \STATE{break crumb of bread}
    \STATE{drop crumb}
    \STATE{take step towards destination}
  \ENDWHILE
  \WHILE{not out of forest}
    \IF{we see at least one crumb}
      \STATE{Go to the closest one}
      \STATE{Pick it up}
    \ELSE
      \STATE{Get eaten by a witch}
    \ENDIF
  \ENDWHILE
\end{algorithmic}