Re: Powers of 5
- From: Phil Carmody <thefatphil_demunged@xxxxxxxxxxx>
- Date: 05 Sep 2006 09:12:33 +0300
"Josh" <jzenker@xxxxxxxxx> writes:
Hi, I'm an undergrad studying computer science. I discovered, while
studying for a computer science final, that I still haven't come up
with an answer to a question that was offered as extra credit on our
first quiz in the course. We were given the following Pascal code.
function power(n: integer): integer;
begin
if n <= 1 then
return (5)
else
return (5 * power(n-1))
end; {power}
We were then asked: "Can you modify the function in such a way that for
arguments of the form 2^k it computes the result with just k+1 calls?"
I'm not especially adept with math, and I have no idea how to approach
the question. Please point me in the right direction; I would really
like to understand this.
If you still don't know the russian peasant algorithm for multiplying,
something that most competant people here probably became aware of
under one of several names or rediscovered themselves while their age
was still in single digits, then either you're going to fail your degree
horribly, or your degree won't be worth the paper it's written on.
However, I'm glad to see that there are people feeding my prejudice
that most modern CS degrees are possibly the best indicator of someone
being _unsuitable_ for a programming job.
The answer's so trivially simple I'm sure you'll get it from others
in the thread.
Phil
--
"Home taping is killing big business profits. We left this side blank
so you can help." -- Dead Kennedys, written upon the B-side of tapes of
/In God We Trust, Inc./.
.
- Follow-Ups:
- Re: Powers of 5
- From: Kevin Buhr
- Re: Powers of 5
- References:
- Powers of 5
- From: Josh
- Powers of 5
- Prev by Date: Re: Powers of 5
- Next by Date: Re: Powers of 5
- Previous by thread: Re: Powers of 5
- Next by thread: Re: Powers of 5
- Index(es):
Relevant Pages
|