home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1993 #1 / NN_1993_1.iso / spool / comp / lang / prolog / 2330 < prev    next >
Encoding:
Text File  |  1993-01-07  |  851 b   |  35 lines

  1. Newsgroups: comp.lang.prolog
  2. Path: sparky!uunet!mcsun!Germany.EU.net!ecrc!acrab60!thom
  3. From: thom@ecrc.de (Thom Fruehwirth)
  4. Subject: British coinage problem
  5. Message-ID: <1993Jan7.141322.22240@ecrc.de>
  6. Keywords: Keep simple problems simple
  7. Sender: news@ecrc.de
  8. Reply-To: thom@ecrc.de
  9. Organization: European Computer-Industry Research Centre GmbH.
  10. Date: Thu, 7 Jan 1993 14:13:22 GMT
  11. Lines: 22
  12.  
  13. min_coins(Value,Coins):- list(Coins),sum_coins(Coins,Value).
  14.  
  15. list([]).
  16. list([X|L]):- list(L).
  17.  
  18. sum_coins([],0).
  19. sum_coins([Coin|Coins],Sum):-
  20.     coin(Coin,Value),
  21.     Value =< Sum,
  22.     NewSum is Sum-Value,
  23.     sum_coins(Coins,NewSum).
  24.  
  25. coin('ten shilling note', 120).
  26. coin(       'half-crown',  30).
  27. coin(           'florin',  24).
  28. coin(         'shilling',  12).
  29. coin(         'sixpence',   6).
  30. coin(   'threepenny bit',   3).
  31. coin(            'penny',   1).
  32.  
  33. % thom
  34.  
  35.