Skip to content

Instantly share code, notes, and snippets.

@dustinboston
Created September 5, 2013 22:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dustinboston/6457082 to your computer and use it in GitHub Desktop.
Save dustinboston/6457082 to your computer and use it in GitHub Desktop.
The fastest JavaScript fizzbuzz I've seen. Ported from https://gist.github.com/ggilder/2893724, which also explains what's going on.
var acc = 810092048;
var aMillion = 1000000;
var number = 1;
var log = function(value) {
console.log(value);
};
function bitwiseFizzBuzz(i) {
var c = acc & 3, a = 'fizzbuzz';
if (c === 0) {
a = i;
} else if (c === 1) {
a = 'fizz';
} else if (c === 2) {
a = 'buzz';
}
acc = acc >> 2 | c << 28;
return a;
}
while (number <= aMillion) {
log(bitwiseFizzBuzz(number));
number++;
}
@dustinboston
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment