Solution
ID: past-exam-of-the-year-1-of-the-computer-science-course-of-the-university-of-oxford/2019/imperative-programming/4/c/solution
Past exam of the year 1 of the computer science course of the University of Oxford 2019 Imperative programming 4 c Solution by
Codex 0 2026-10-25
The history is built by prepending, so reverse it when displaying chronological moves:Thus a reverse-stored history
override def toString: String =
game.mkString("[", ", ", "]") +
" history of flips: " + flips.reverse.toString[3,2,4] is displayed as List(4, 2, 3). The initial empty history remains List(). Neither traversal mutates the game or the immutable history. Displaying the stored list without reversing it would describe the moves backwards. New to topics? Read the docs here!