Hacker News new | ask | show | jobs
by contravariant 4069 days ago
That's not really an optimal way to check divisibility though, if you want to be quick try:

    fizz = (uint)i*2863311531 <= (uint)i;
    buzz = (uint)i*3435973837 <= (uint)i;
Should work for fine for i<=1000.

Edit: changed "<" to "<=", otherwise it fails when i=0.

1 comments

He mentions ruby uses bigintegers, while this assumes something else, right?
The above assumes unsigned 32bit integers. It abuses integer overflow. Perhaps I should have stated that more explicitly.