Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.forth > #24073
| From | Paul Rubin <no.email@nospam.invalid> |
|---|---|
| Newsgroups | comp.lang.forth |
| Subject | Re: Euler 433 : analyzing euclids algo |
| Date | 2013-07-01 17:37 -0700 |
| Organization | Nightsong/Fort GNOX |
| Message-ID | <7xip0tztj9.fsf@ruckus2.brouhaha.com> (permalink) |
| References | <51d0db5a$0$3167$e4fe514c@dreader36.news.xs4all.nl> |
albert@spenarnc.xs4all.nl (Albert van der Horst) writes:
> int gcd(int a,int b,int *d)
> {
> (*d)=(*d)+1;
> if(a==0)
> return *d;
> else
> return gcd(b%a,a,d);
> }
> Note that a pointer to a variable is used
Traditional functional style would use a separate function with an extra
arg, something like:
int gcd(int a, int b) {
return gcd2(a, b, 1);
}
int gcd2(int a, int b, int d) {
if (a == 0) return d;
return gcd2(b%a, a, d+1);
}
hopefully a good Forth compiler would do the right thing with the
corresponding Forth code.
Back to comp.lang.forth | Previous | Next — Previous in thread | Find similar
Euler 433 : analyzing euclids algo albert@spenarnc.xs4all.nl (Albert van der Horst) - 2013-07-01 01:28 +0000
Re: Euler 433 : analyzing euclids algo m.a.m.hendrix@tue.nl - 2013-07-01 01:03 -0700
Re: Euler 433 : analyzing euclids algo Andrew Haley <andrew29@littlepinkcloud.invalid> - 2013-07-01 03:20 -0500
Re: Euler 433 : analyzing euclids algo m.a.m.hendrix@tue.nl - 2013-07-01 01:30 -0700
Re: Euler 433 : analyzing euclids algo albert@spenarnc.xs4all.nl (Albert van der Horst) - 2013-07-01 09:59 +0000
Re: Euler 433 : analyzing euclids algo anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2013-07-01 11:43 +0000
Re: Euler 433 : analyzing euclids algo albert@spenarnc.xs4all.nl (Albert van der Horst) - 2013-07-01 19:01 +0000
Re: Euler 433 : analyzing euclids algo anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2013-07-02 07:30 +0000
Re: Euler 433 : analyzing euclids algo "WJ" <w_a_x_man@yahoo.com> - 2013-07-01 15:19 +0000
Re: Euler 433 : analyzing euclids algo Alex McDonald <blog@rivadpm.com> - 2013-07-01 09:14 -0700
Re: Euler 433 : analyzing euclids algo albert@spenarnc.xs4all.nl (Albert van der Horst) - 2013-07-01 19:05 +0000
Re: Euler 433 : analyzing euclids algo Mark Wills <markrobertwills@yahoo.co.uk> - 2013-07-02 00:02 -0700
Re: Euler 433 : analyzing euclids algo "WJ" <w_a_x_man@yahoo.com> - 2013-07-03 01:32 +0000
Re: Euler 433 : analyzing euclids algo Paul Rubin <no.email@nospam.invalid> - 2013-07-01 17:37 -0700
csiph-web