Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database And Expert Systems Applications Dexa 2022 Workshops 33rd International Conference Dexa 2022 Vienna Austria August 22 24 2022 In Computer And Information Science 33

Authors: Gabriele Kotsis ,A Min Tjoa ,Ismail Khalil ,Bernhard Moser ,Alfred Taudes ,Atif Mashkoor ,Johannes Sametinger ,Jorge Martinez-Gil ,Florian Sobieczky ,Lukas Fischer ,Rudolf Ramler ,Maqbool Khan ,Gerald Czech

1st Edition

3031143426, 978-3031143427

More Books

Students also viewed these Databases questions