Question
Please write it in Prolog Write a Prolog program for a predicate change/3 such that change(Cs,X,Ns) holds if and only if - Cs is a
Please write it in Prolog
Write a Prolog program for a predicate change/3 such that change(Cs,X,Ns) holds if and only if - Cs is a list of nonnegative integers representing the denominations of coins, for example if Cs = [10,5,2], this means that we consider 10p, 5p and 2p coins.
- X is a nonnegative integer representing an amount of money.
- Ns is a list of nonnegative integers, of the same length as Cs, saying how the amount X can be composed from the available coins.
For example, the query ?- change([10,5,2],17,Ns).
should yield the answers
Ns = [1, 1, 1] ;
Ns = [0, 3, 1] ;
Ns = [0, 1, 6] ;
false.
since 17 = 1 10 + 1 5 + 1 2 = 0 10 + 3 5 + 1 2 = 0 10 + 1 5 + 6 2
and there is no other way of writing 17 as the sum of (nonnegative integer) multiples of 10, 5 and 2.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started