Weekly exercises in INF3110 - ML IV
week 42 13-17.10.2008
Exercise 1
----------
Exercise 8.1 in Mitchell's book
Exercise 2
----------
Exercise 8.3 in Mitchell's book
Exercise 3
----------
Exercise 8.4 in Mitchell's book
Exercise 4
----------
Exercise 8.7 in Mitchell's book
Exercise 5
----------
(Taken from Paulson's book "ML for the working programmer")
Given a certain amount of money and a list of coin values, we would like to receive change using the largest coins possible. This is easy if the coins values are supplied in decreasing order. The following naive algorithm implements it:
fun change (coinvals, 0) = []
| change (c::coinvals, amount) =
if amount int list" in ML which implements a backtracking algorithm for solving the above problem using exceptions (define "exception Change;"). These are some examples of expected results:
- changeBack([5,2], 17);
val it = [5,5,5,2] : int list
- changeBack([], 12);
uncaught exception Change
- changeBack([5,2], 16);
val it = [5,5,2,2,2] : int list