3 ms·
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*343597
by contravariant 12y 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.
- kazagistar 12y agoHe mentions ruby uses bigintegers, while this assumes something else, right?
- contravariant 12y agoThe above assumes unsigned 32bit integers. It abuses integer overflow. Perhaps I should have stated that more explicitly.