How to resolve the algorithm Count the coins step by step in the Prolog programming language

Published on 12 May 2024 09:40 PM

How to resolve the algorithm Count the coins step by step in the Prolog programming language

Table of Contents

Problem Statement

There are four types of common coins in   US   currency:

There are six ways to make change for 15 cents:

How many ways are there to make change for a dollar using these common coins?     (1 dollar = 100 cents).

Less common are dollar coins (100 cents);   and very rare are half dollars (50 cents).   With the addition of these two coins, how many ways are there to make change for $1000? (Note:   the answer is larger than   232).

Let's start with the solution:

Step by Step solution about How to resolve the algorithm Count the coins step by step in the Prolog programming language

Source code in the prolog programming language

:- use_module(library(clpfd)).

% Basic, Q = Quarter, D = Dime, N = Nickel, P = Penny
coins(Q, D, N, P, T) :-
	[Q,D,N,P] ins 0..T,
	T #= (Q * 25) + (D * 10) + (N * 5) + P.

coins_for(T) :-
	coins(Q,D,N,P,T),
	maplist(indomain, [Q,D,N,P]).


  

You may also check:How to resolve the algorithm Additive primes step by step in the Julia programming language
You may also check:How to resolve the algorithm Colorful numbers step by step in the Go programming language
You may also check:How to resolve the algorithm Temperature conversion step by step in the Ezhil programming language
You may also check:How to resolve the algorithm Strip whitespace from a string/Top and tail step by step in the Nemerle programming language
You may also check:How to resolve the algorithm Create an HTML table step by step in the EchoLisp programming language