Submission directions: Please turn in both printed and electronic copies of your code. The print submission is due in quiz section on the due date above (or later that day). You may e-mail the electronic copies to Keunwoo (klee@cs) anytime the same day. For full credit, you must follow the submission guidelines.
You don't need to hand in anything for Questions 1 or 2 -- these are just to give you some practice.Define the append and sum relations as follows:
append([],L,L). append([H|T],L,[H|U]) :- append(T,L,U). sum([],0). sum([X|Xs],X+S) :- sum(Xs,S).Try append on the following. In each case reject the answers to see what happens when CLP(R) backtracks.
append([a,b,c],[w,x,y,z],L). append([a,b],Y,[a,b,c,d]). append([a,c],Y,[a,b,c,d]). append(X,Y,[a,b,c,d]). append(X,Y,Z).Now try sum on the following, again backtracking when possible.
sum([5,10,20],N). sum([5,10,20],8). sum([5,X],100). sum([5,X,Y],100). sum(A,100).
coins(10,L)should succeed with L=[10], i.e. one way of getting 10 cents is a single dime. On backtracking it should also succeed with L=[5,5], i.e. two nickels.
It's OK to return the same answer a second time when you backtrack -- for example, if you are finding combinations for 15 cents, you can return [10,5] and also [5,10].
Using your coins rule: