division by 7 efficiently ???
Neil Cerutti
horpner at yahoo.com
Fri Feb 2 09:01:21 EST 2007
On 2007-02-01, Michael Yanowitz <m.yanowitz at kearfott.com> wrote:
> I think it is off by 1 in small numbers, off by a little more with large
> numbers:
>>>> def div7 (N):
> ... return (N>>3) + ((N-7*(N>>3))>>3)
> ...
>>>> div7 (70)
> 9
>>>> div7 (77)
> 10
>>>> div7 (700)
> 98
>>>> div7 (7)
> 0
>>>> div7 (10)
> 1
>>>> div7 (14)
> 1
>>>> div7 (21)
> 2
>>>> div7 (700)
> 98
>>>> div7 (7000)
> 984
>
Heh, heh. That's reminding of the "fabulous" O(n) Dropsort
algorithm I saw linked from Effbot's blog.
--
Neil Cerutti
I'm tired of hearing about money, money, money, money, money. I just want to
play the game, drink Pepsi, wear Reebok. --Shaquille O'Neal
More information about the Python-list
mailing list