Re: Powers of 5



Rick Decker wrote:

<snip>

Powers of 5 of the form 2^k (i.e. 5^(2^k)) can be computed quickly
by successive squaring. For example,

5^16 = (5^8)^2

5^8 = (5^4)^2

5^4 = (5^2)^2

5^2 = (5^1)^2

This should give you the modified algorithm almost immediately.

That's perfect. I wish I had thought of that. I rewrote the function
in Python for the sake of being concise, but now the function takes k
rather than 2^k as its argument. So I guess I haven't really answered
the question.

def power(k):
if (k <= 1):
return 5
else:
return power(k-1)**2

<snip>

Also, I'm sort of curious what school is still using Pascal as an
introductory language. Not that I'm complaining--I think Pascal
could still be a righteous choice for an intro vehicle; I'd just
like to know what school still has the stones to resist jumping
on the C#/C++/C/Java bandwagons.

That would be Drexel University. The course I've been taking covers
data structures and algorithms, and therefore the programming component
is small. Courses with greater emphasis on programming have entered
into a sordid love affair with OO languages, especially C++ and Java.
At least, that's how it seems to an outsider. (My home institution is
the University of Chicago. They started us with Scheme, which made me
loathe nested parantheses for a while.)

At any rate, I digress. I'm just missing how to get the function to
take 2^k as its argument. If you don't mind helping a little more, I
would be grateful.

--
Josh Zenker

.