division by 7 efficiently ???

garrickp at gmail.com garrickp at gmail.com
Tue Feb 6 19:05:24 EST 2007


On Feb 6, 4:54 pm, "John Machin" <sjmac... at lexicon.net> wrote:
> Recursive? Bzzzt!

I woudl be happy to hear your alternative, which doesn't depend on
language specific tricks. Thus far, all you have suggested is using an
alternative form of the division function, which I would consider to
be outside the spirit of the question (though I have been wrong many
times before).

> Might it not be better to halve the interval at each iteration instead
> of calling a random number function? mid = (lo + hi) >> 1 looks
> permitted and cheap to me. Also you don't run the risk of it taking a
> very high number of iterations to get a result.

I had considered this, but to halve, you need to divide by 2. Using
random, while potentially increasing the number of iterations, removes
the dependency of language tricks and division.

> Did you notice the important word *efficiently* in line 1 of the spec?
> Even after ripping out recursion and random numbers, your proposed
> solution is still way off the pace.

Again, I look forward to reading your solution.

Respectfully, G.




More information about the Python-list mailing list