Created
August 2, 2018 20:25
-
-
Save florean/3f0e7fd9ed3c92819f3fc3c89de9d7ee to your computer and use it in GitHub Desktop.
A simple FizzBuzz that uses counters instead of division.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
int main() { | |
unsigned int fb = 0x0F0305; // 15 for fizzbuzz, 3 for fizz, and 5 for buzz | |
for (unsigned int i = 1; i < 101; i++) { | |
fb -= 0x010101; // Decrement one from each counter. | |
if (fb < 0X010000) { | |
fb = 0x0F0305; // Reset all counters to original value; | |
printf("fizzbuzz\n"); | |
} else if ((fb & 0xFFFF) < 0x0100) { | |
fb += 0x0300; // Reset the fizz counter to 3. | |
printf("fizz\n"); | |
} else if (!(fb & 0xFF)) { | |
fb += 5; // Reset the buzz counter to 5. | |
printf("buzz\n"); | |
} else { printf("%d\n", i); } | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment