Re: Powers of 5



"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./.
.



Relevant Pages

  • Re: Powers of 5
    ... 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 ... this algorithm is flat wrong. ...
    (sci.math)
  • Re: Thank God for students...
    ... Some of them students know quite alot about computers if they're studying ... computer science. ...
    (uk.telecom.broadband)