Hey lads, wanna see a fizzbuzz implementation that doesn't use booleans?String[][] arr = {{"fizzbuzz\n","fizz\n"},{"buzz\n","%d\n"}};
for (int i = 1; i <= 100; ++i) System.out.printf(arr[i%3 - (i%3 >> 1)][(i%5 - (i%5 >> 1)) - ((i%5 - (i%5 >> 1)) >> 1)], i);
pic unrelated
Except for the for loop, of course.
>>62466350
Nice, collapsing loops into optimized tesseracts is the best drug anon.
I am a brainlet, can someone explain what is happening here? how does this work?
>>62467872
i%3 can result in 0, 1, or 2;
0 - (0 >> 1) = 0; 1 - (1 >> 1) = 1; 2 - (2 >> 1) = 1.
i%5 can result in 0, 1, 2, 3, or 4;
3 - (3 >> 1) = 2; 4 - (4 >> 1) = 2; reapplying the operation for the resultant 2s yield 1s (and reapplying for 0 or 1 yields themselves).
so nesting the [x%y - (x%y >> 1)] n = floor(log_2(y)) times will yield 1 for x%y != 0 and 0 for x%y = 0
so now we can make a 2 dimensional array 2x2with one of the dimensions handling divisibility by 3 and the other for divisibility by 5. (i.e. [0][0] is the state of being divisible by both [0][1] being divisible by 3 only etc.)
and the printf is to handle when they're not divisible by either.