Re: Powers of 5
- From: James Waldby <j-waldby@xxxxxxxx>
- Date: Mon, 04 Sep 2006 21:11:07 -0600
Josh wrote:
Rick Decker wrote:....
....Powers of 5 of the form 2^k (i.e. 5^(2^k)) can be computed quickly
by successive squaring. For example,
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
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.
You merely replaced "return (5 * power(n-1))" with
"return power(k-1)**2". Instead, make the function
split three ways -
if n <= 1 return 5,
else if n is even return the square of something,
else return power(n-1)*5.
[Helpful example: x^14 = (x^7)^2.]
-jiw
.
- Follow-Ups:
- Re: Powers of 5
- From: Phil Carmody
- Re: Powers of 5
- From: Josh Zenker
- Re: Powers of 5
- References:
- Powers of 5
- From: Josh
- Re: Powers of 5
- From: Rick Decker
- Re: Powers of 5
- From: Josh
- Powers of 5
- Prev by Date: Measure Theory
- Next by Date: - Measure Theory -
- Previous by thread: Re: Powers of 5
- Next by thread: Re: Powers of 5
- Index(es):
Relevant Pages
|
Loading