division by 7 efficiently ???

Nicko usenet at nicko.org
Thu Feb 1 08:00:32 EST 2007


On Feb 1, 3:13 am, krypto.wiz... at gmail.com wrote:
> Its not an homework. I appeared for EA sports interview last month. I
> was asked this question and I got it wrong. I have already fidlled
> around with the answer but I don't know the correct reasoning behind
> it.

In that case, observer that a/b == a * (1/b), and if b is constant you
can compute (1/b) in advance.  Since the problem was set by game
programmers I'd hazard that they are OK with relatively limited
precision and the answer that they were looking for was:
    a = (b * 04444444445L) >> 32
Note that the constant there is in octal.

    Nicko




More information about the Python-list mailing list