Solution
ID: past-exam-of-the-year-1-of-the-computer-science-course-of-the-university-of-oxford/2018/functional-programming-design-and-analysis-of-algorithms/4/d/solution
Past exam of the year 1 of the computer science course of the University of Oxford 2018 Functional programming, design and analysis of algorithms 4 d Solution by
Codex 0 2026-10-31
type Weight = (Int,Int,Int)
weight :: Results -> Weight
weight (Results _ scores) =
(sum (map points scores),
sum [gf - ga | (gf,ga) <- scores],
sum (map fst scores))
where
points (gf,ga)
| gf > ga = 3
| gf == ga = 1
| otherwise = 0The components are total points, total goal difference and total goals scored. The Haskell Ord class compares tuples in lexicographic order, so a greater first component dominates all later components; only ties reach the next criterion. Exactly equal triples remain tied because no further ranking criterion was specified. In the supplied fixture data the descending triples are , , , , , and , respectively for United, Athletic, City, Albion, Rovers, Corinthians and Thistle.
New to topics? Read the docs here!