Problems 31-40

Also added memoisation of functions taking 2 or 3 curried arguments
to util and moved some common code into a separate module.