/*
Coins sum problem in Picat.
From
Richard Wiseman "It's the Friday Puzzle"
http://richardwiseman.wordpress.com/2013/07/12/its-the-friday-puzzle-219/
"""
How can you use 50 American coins to add up to a dollar? The coins available are a
penny (1 cent), a nickel (5 cents), a dime (10 cents), a quarter (25 cents),
and a half-dollar (50 cents).
"""
Here we show to different approaches, both using CP.
This Picat model was created by Hakan Kjellerstrand, hakank@gmail.com
See also my Picat page: http://www.hakank.org/picat/
*/
% import util.
import cp.
main => go, go2.
go =>
L = new_list(50), % we have 50 coins
L :: [1,5,10,25,50], % acceptable values
sum(L) #= 100, % sums to a dollar
increasing(L), % symmetry breaking
All=solve_all(L),
foreach(L2 in All) writeln(L2) end,
nl.
go2 =>
L = [One,Five,Ten,TwentyFive,Fifty],
L :: 0..100,
1*One+5*Five+10*Ten+25*TwentyFive+50*Fifty #= 100, % sums to a dollar
One+Five+Ten+TwentyFive+Fifty #= 50, % fifty coins
All = solve_all(L),
foreach(L2 in All) writeln(L2) end,
nl.
increasing(List) =>
foreach(I in 2..List.length) List[I-1] #=< List[I] end.