Last active
January 16, 2021 02:36
-
-
Save lfnoise/cf3deb38006458bb4c5f74ea4c27126a to your computer and use it in GitHub Desktop.
An implementation of fizzbuzz with only one modulo and one comparison per cycle.
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
// | |
// main.c | |
// fizzbuzz | |
// | |
// Created by James McCartney on 1/15/21. | |
// | |
#include <stdio.h> | |
void fizzbuzz(int n) | |
{ | |
static const char* format[4] = {"%d\n", "fizz\n", "buzz\n", "fizzbuzz\n"}; | |
for (int i = 0; i < n; ++i) { | |
int j = 0x3 & (0x01241843 >> ((i % 15) << 1)); | |
printf(format[j], i); | |
} | |
} | |
int main(int argc, const char * argv[]) | |
{ | |
fizzbuzz(101); | |
return 0; | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment