division by 7 efficiently ???

Marc 'BlackJack' Rintsch bj_666 at gmx.net
Thu Feb 1 03:13:13 EST 2007


In <1170313815.362394.92400 at a34g2000cwb.googlegroups.com>, Paul McGuire
wrote:

> On Jan 31, 11:36 pm, "Paddy" <paddy3... at netscape.net> wrote:
>> On Feb 1, 2:42 am, krypto.wiz... at gmail.com wrote:
>>
>> > How to divide a number by 7 efficiently without using - or / operator.
>> > We can use the bit operators. I was thinking about bit shift operator
>> > but I don't know the correct answer.
>> >>> int.__div__(14,2)
>> 7
>>
>> Not a minus or division operator in sight ;-)
>>
>> - Paddy.
> 
> Now I'm confused - was the OP trying to divide by 7 or 2?

I read it as divide by 7.  And the `int.__div__()` Method limits this
somehow -- a more polymorphic approach would be::

 import operator
 operator.div(14, 7)

:-)

Ciao,
	Marc 'BlackJack' Rintsch



More information about the Python-list mailing list