Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.forth > #13098
| From | Paul Rubin <no.email@nospam.invalid> |
|---|---|
| Newsgroups | comp.lang.forth |
| Subject | Re: Euro's and Dollars. |
| References | <m5tu4r.9ba@spenarnc.xs4all.nl> <m5vfli.1em@spenarnc.xs4all.nl> <ZeadnXrO7ddPJH3SnZ2dnUVZ8iudnZ2d@supernews.com> <7x4nq7tbpa.fsf@ruckus.brouhaha.com> <m5wble.34c@spenarnc.xs4all.nl> |
| Date | 2012-06-19 23:51 -0700 |
| Message-ID | <7xoboexypk.fsf@ruckus.brouhaha.com> (permalink) |
| Organization | Nightsong/Fort GNOX |
Albert van der Horst <albert@spenarnc.xs4all.nl> writes:
> The book shows its age (1990) with sentences like:
> "It will take quite a while for that 292 to be computed."
>
> (Actually more like 2 mS in Forth, I don't know yet how
> to measure it in Scheme, but it is not noticeable.)
Here is a memoized python version. With the memoization turned off, the
euro calculation takes a noticable time (maybe 0.2 sec). With
memoization there's no noticable pause.
================================================================
def memoize(f, sentinel=object()):
memo = {}
def m(*args):
if args in memo:
return memo[args]
memo[args] = v = f(*args)
return v
return m
@memoize
def cc(amount, coins):
if not(coins) or amount < 0: return 0
if amount == 0: return 1
return cc(amount-coins[0],coins) + cc(amount,coins[1:])
print 'dollar',cc(100,(1,5,10,25,50))
print 'euro',cc(100,(1,2,5,10,20,50))
Back to comp.lang.forth | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll 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