Skip to content

Instantly share code, notes, and snippets.

@badamczewski
Created June 24, 2015 11:03
Show Gist options
  • Save badamczewski/5978e8004f96ee061ffa to your computer and use it in GitHub Desktop.
Save badamczewski/5978e8004f96ee061ffa to your computer and use it in GitHub Desktop.
branchless fizzbuzz.
object[] arr = new object[] { null, "fizz", "buzz", "fizzbuzz" };
int r = 0;
int bf = 1;
int bb = 1;
int a1, a2 = 0;
for (int i = 1; i < 100000000; i++)
{
a1 = a2 = 0;
if (bf > (3 - 1)) { bf = 0; a1 = 1; }
bf += 1;
if (bb > (5 - 1)) { bb = 0; a2 = 1; }
bb += 1;
r = a1 + a2 * 2;
arr[0] = i;
var s = arr[r];
Console.WriteLine(s);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment