Article View: comp.lang.logo
Article #256Re: um, maybe this is a silly question
From: Brian Harvey
Date: Tue, 13 Oct 1992 17:42
Date: Tue, 13 Oct 1992 17:42
26 lines
1718 bytes
1718 bytes
Max Hailperin <max@nic.gac.edu> writes:
|int factorial_product(int x, int n){ /* computes x * n! */
| if (n == 0)
| return x; /* because x * 0! = x * 1 = x */
| else
| return factorial_product(x*n, n-1);
| /* because x * n! = x * (n * (n-1)!) = (x*n) * (n-1)! */
| }
|
|int Factorial(int n) {
| return factorial_product(1, n); /* because n! = 1 * n! */
| }
I agree that this is a debuggable program. My problem with it is that it's
not something anyone would naturally think of. The original problem is to
compute n! and instead of getting CLOSER to the solution by computing (n-1)!
you get FARTHER AWAY by computing x*n! instead. This turns out to be helpful
but it's a total rabbit-from-hat.
Again, if your interest is in loop invariants rather than in factorials,
this is a fine example. But I think it would be a terrible thing to teach
loop invariants to high school kids. That's an example of what I call
"turning computer programming into trigonometry" -- making it boring and
confusing and full of facts to memorize, instead of an immediate source
of power. [Now I'm going to hear from all the irate trig teachers! :-)]
Technical Details
Message-ID:
<1bf1qlINNgj5@agate.berkeley.edu>Path:
arc1-ca.pugleaf.net!sparky!uunet!stanford.edu!agate!anarres.CS.Berkeley.EDU!bhReferences:
<1992Oct12.163421.24051@sctc.com> <1992Oct13.035329.19258@pasteur.Berkeley.EDU> <MAX.92Oct13121742@Kolmogorov.gac.edu>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!sparky!uunet!stanford.edu!agate!anarres.CS.Berkeley.EDU!bh From: bh@anarres.CS.Berkeley.EDU (Brian Harvey) Newsgroups: comp.lang.logo Subject: Re: um, maybe this is a silly question Date: 13 Oct 1992 17:42:45 GMT Organization: University of California, Berkeley Lines: 26 Distribution: usa Message-ID: <1bf1qlINNgj5@agate.berkeley.edu> References: <1992Oct12.163421.24051@sctc.com> <1992Oct13.035329.19258@pasteur.Berkeley.EDU> <MAX.92Oct13121742@Kolmogorov.gac.edu> NNTP-Posting-Host: anarres.cs.berkeley.edu