MAS2008 Scientific Computing: Lab 7 Solutions

Task 1: Unit tests for anagrams

See this notebook:
       
Counting anagrams View Download

Task 2: Debugging lists of subsets

The function list_ramps_b(m, n) is correct except when m is zero. The simplest way to fix it is just to check whether m is zero at the beginning, and return [[]] in that case.

The function list_ramps_c(m, n) is also almost correct, but it generates the list of ramps where the last entry is strictly less than n, and we are supposed to allow for the last entry to be equal to n. This can be fixed by changing range(max([0]+L[i]), n) to range(max([0]+L[i]), n+1).

The function list_ramps_d(m, n) generates the correct set of ramps, but they do not come out listed in lexicographic order. One could just use the function sorted() to put them in the right order, but sorting is a moderately expensive operation, so it is better to use a different algorithm that produces the right order automatically.

Task 3: Cloning a repository

There are no solutions as such for this, but I am happy to answer questions if you had trouble with it.