Best search algorithm to find condition within a range
steve+comp.lang.python at pearwood.info
Wed Apr 8 02:18:20 CEST 2015
On Wed, 8 Apr 2015 03:07 am, jonas.thornvall at gmail.com wrote:
> So you can tell me the first (higest) digit of the integer
> Using base 429496729?
That makes no sense. With base 429496729 you need to have 429496729
different digits. Of course it is possible that, just by chance, you end up
with something that only includes the digits 0 through 9. Of course that is
possible, just like there are decimal numbers which only use digits 0
through 1, e.g. 10001.
If you want to go the other way, and convert s FROM decimal INTO base
429496729, you need to tell us what digits to use. You need 429496729
> How long time did it take to find it?
A tiny fraction of a second.
py> from timeit import Timer
py> setup = "s
py> t = Timer("s; max(s)", setup)
That's just over 7 seconds to calculate both the first and the highest digit
one million times, or about 7 microseconds each time.
More information about the Python-list