Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.forth > #13054

Re: Euro's and Dollars.

Path csiph.com!usenet.pasdenom.info!gegeweb.org!de-l.enfer-du-nord.net!feeder1.enfer-du-nord.net!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail
From vandys@vsta.org
Newsgroups comp.lang.forth
Subject Re: Euro's and Dollars.
Date 19 Jun 2012 00:49:29 GMT
Lines 42
Message-ID <a4a0kpFeidU1@mid.individual.net> (permalink)
References <m5tu4r.9ba@spenarnc.xs4all.nl>
X-Trace individual.net eplzCpekoODPEzdqwt8FAgQCqm5GCxrZtr7afla0v51BLl1RlmyviDNNusgfp1sl73
X-Orig-Path not-for-mail
Cancel-Lock sha1:eXms1s7qQ3nfltQfb9yikjV5nEI=
User-Agent tin/1.8.3-20070201 ("Scotasay") (UNIX) (Linux/2.6.32-41-generic-pae (i686))
Xref csiph.com comp.lang.forth:13054

Show key headers only | View raw


Albert van der Horst <albert@spenarnc.xs4all.nl> wrote:
> In studying Scheme I came across the example program to count
> in how many ways one dollar can be changed.

From: vandys@vsta.org
To: Albert van der Horst <albert@spenarnc.xs4all.nl>
Subject: Re: Euro's and Dollars.
In-Reply-To: <m5tu4r.9ba@spenarnc.xs4all.nl>
X-Newsgroups: comp.lang.forth

In article <m5tu4r.9ba@spenarnc.xs4all.nl> you wrote:
> In studying Scheme I came across the example program to count
> in how many ways one dollar can be changed.

Here's the search in Prolog, FWIW (not tested, just wanted to play with
the idea):

% A solution
change(_, 0, _, Solve) :- debug("solve", Solve), !, fail.

% No solution
change([], _, _) :- !, fail.
change([Coin|_], Balance, _) :-
    Coin > Balance, !, fail.

% Apply current coin
change(Coins, Balance, Solve) :-
    [Coin|_]=Coins,
    Balance2 is Balance-Coin,
    change(Coins, Balance2, [Coin|Solve]).

% Step down to next coin
change([_|Coins], Balance, Solve) :- change(Coins, Balance, Solve).

Invocation for US money WRT one dollar:

change([1, 5, 10, 25, 50], 100, []).

-- 
Andy Valencia
Home page: http://www.vsta.org/andy/
To contact me: http://www.vsta.org/contact/andy.html

Back to comp.lang.forth | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Euro's and Dollars. Albert van der Horst <albert@spenarnc.xs4all.nl> - 2012-06-18 19:00 +0000
  Re: Euro's and Dollars. "A. K." <akk@nospam.org> - 2012-06-18 23:18 +0200
    Re: Euro's and Dollars. Mark Wills <markrobertwills@yahoo.co.uk> - 2012-06-19 00:20 -0700
      Re: Euro's and Dollars. "Elizabeth D. Rather" <erather@forth.com> - 2012-06-18 21:51 -1000
  Re: Euro's and Dollars. vandys@vsta.org - 2012-06-19 00:49 +0000
    Re: Euro's and Dollars. Spam@ControlQ.com - 2012-06-18 21:43 -0400
      Re: Euro's and Dollars. "A. K." <akk@nospam.org> - 2012-06-19 07:20 +0200
        Re: Euro's and Dollars. Ecki <ecki@intershop.de> - 2012-06-19 09:26 +0200
          Re: Euro's and Dollars. Albert van der Horst <albert@spenarnc.xs4all.nl> - 2012-06-19 15:58 +0000
            Re: Euro's and Dollars. "A. K." <akk@nospam.org> - 2012-06-19 19:58 +0200
              Re: Euro's and Dollars. Albert van der Horst <albert@spenarnc.xs4all.nl> - 2012-06-20 01:31 +0000
                Re: Euro's and Dollars. "A. K." <akk@nospam.org> - 2012-06-20 07:15 +0200
            Re: Euro's and Dollars. Ecki <ecki@intershop.de> - 2012-06-20 10:15 +0200
            Re: Euro's and Dollars. anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2012-06-20 10:46 +0000
              Re: Euro's and Dollars. Albert van der Horst <albert@spenarnc.xs4all.nl> - 2012-06-20 17:39 +0000
                Re: Euro's and Dollars. anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2012-06-21 16:21 +0000
                Re: Euro's and Dollars. Andrew Haley <andrew29@littlepinkcloud.invalid> - 2012-06-21 11:58 -0500
                Re: Euro's and Dollars. anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2012-06-22 14:57 +0000
                Re: Euro's and Dollars. Albert van der Horst <albert@spenarnc.xs4all.nl> - 2012-06-21 20:38 +0000
      Re: Euro's and Dollars. vandys@vsta.org - 2012-06-19 15:49 +0000
    Re: Euro's and Dollars. Albert van der Horst <albert@spenarnc.xs4all.nl> - 2012-06-19 15:43 +0000
      Re: Euro's and Dollars. vandys@vsta.org - 2012-06-19 15:51 +0000
  Re: Euro's and Dollars. Albert van der Horst <albert@spenarnc.xs4all.nl> - 2012-06-19 15:41 +0000
    Re: Euro's and Dollars. Paul Rubin <no.email@nospam.invalid> - 2012-06-19 10:26 -0700
      Re: Euro's and Dollars. Paul Rubin <no.email@nospam.invalid> - 2012-06-19 23:34 -0700
    Re: Euro's and Dollars. Andrew Haley <andrew29@littlepinkcloud.invalid> - 2012-06-19 12:41 -0500
      Re: Euro's and Dollars. Paul Rubin <no.email@nospam.invalid> - 2012-06-19 11:10 -0700
        Re: Euro's and Dollars. Albert van der Horst <albert@spenarnc.xs4all.nl> - 2012-06-20 03:12 +0000
          Re: Euro's and Dollars. Paul Rubin <no.email@nospam.invalid> - 2012-06-19 23:51 -0700
        Re: Euro's and Dollars. Andrew Haley <andrew29@littlepinkcloud.invalid> - 2012-06-20 03:15 -0500

csiph-web