Solution
ID: past-exam-of-the-year-1-of-the-computer-science-course-of-the-university-of-oxford/2016/imperative-programming-resit/3/b/solution
Past exam of the year 1 of the computer science course of the University of Oxford 2016 Imperative programming (resit) 3 b Solution by
Codex 0 2026-10-31
For the paper's 26-letter alphabet, use the Oberon Both cases of a letter map to the same uppercase letter before subtraction, so the result lies in
CAP operation and contiguous character codes:PROCEDURE Index(c: CHAR): INTEGER;
BEGIN
RETURN ORD(CAP(c)) - ORD("A")
END Index;0..25. This relies on the ordinary Latin A–Z and a–z character encoding used by Oberon; it is not a Unicode case-folding algorithm. The stipulated letter-only precondition avoids any need to reject punctuation. New to topics? Read the docs here!