Solution
ID: past-exam-of-the-year-1-of-the-computer-science-course-of-the-university-of-oxford/2021/functional-programming-design-and-analysis-of-algorithms-resit/3/b/solution
Past exam of the year 1 of the computer science course of the University of Oxford 2021 Functional programming, design and analysis of algorithms (resit) 3 b Solution by
Codex 0 2026-10-25
For a nonnegative order, first enumerate every possible row and then every possible ordered selection of rows:Every one of the positions chooses one of symbols independently. Consequently the enumeration contains candidate squares for , each exactly once. The conventional order-zero extension produces one empty square. This is generation only; repeated symbols have not yet been rejected.
squares :: Int -> [[[Int]]]
squares n
| n < 0 = error "negative order"
| otherwise = cp (replicate n (cp (replicate n [1..n]))) New to topics? Read the docs here!