I need help with a homework. Using Prolog

I need help with a homework. Using Prolog.

The exercise is about a dispensing machine.

The machine has a limited amount of bills and coins of certain denominations.

For example, if $8 needs to be returned to the customer, it can be completed using a $5 coin and 3 $1 coins. But if the machine does not have $5 coins, it must dispense 8 $1 coins.

Define a form to specify both the cash available and the amount dispensed. The result should be displayed by means of such a representation (a list, for example).

The program should display all possible combinations of coins or bills that complete the amount when asked for alternative answers (not all answers should always be displayed, only when other solutions are requested).

If the machine has, for example, $4150 distributed as follows:

  • 1 bill of $1000
  • 4 coins of $500
  • 10 coins of $100
  • 3 coins of $50

and you must return an amount of $1550, you could hand over:

  • 1 $1000 bill, 1 $500 coin and 1 $50 coin.
  • 1 bill of $1000, 5 coins of $100 and 1 coin of $50
  • 1 bill of $1000, 4 coins of $100 and 3 coins of $50
  • 3 coins of $500 and one coin of $50
  • 2 coins of $500, 5 coins of $100 and 1 coin of $50
  • 2 coins of $500, 4 coins of $100 and 3 coins of $50
  • 1 coin of $500, 10 coins of $100 and 1 coin of $50
  • 1 coin of $500, 9 coins from $100 and 3 coins of $50

The query could be something similar to:

While you can ask these type of homework questions here, do not expect an answer here.

To get started learning Prolog please use one of the free introduction books. :slightly_smiling_face: