Last active
December 19, 2015 07:39
-
-
Save cronin101/5919905 to your computer and use it in GitHub Desktop.
FizzBuzz from 1 to N (supplied as command-line argument) and exiting gracefully without using loops, conditionals, or segfaults - in C.
This file contains hidden or 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> | |
| #include <stdlib.h> | |
| int i(const int i) { printf("%d\n", i); return i; } | |
| int f(const int i) { printf("Fizz\n"); return i; } | |
| int b(const int i) { printf("Buzz\n"); return i; } | |
| int fb(const int i) { printf("FizzBuzz\n"); return i; } | |
| int (* PC[15])(int i) = { i,i,f,i,b,f,i,i,f,b,i,f,i,i,fb }; // Printer Cycle | |
| int go(const int arg) { | |
| return PC[(arg - 1) % 15](arg) + 1; | |
| } | |
| int stop(const int arg) { | |
| PC[(arg - 1) % 15](arg); | |
| exit(0); | |
| } | |
| int (* LC[2]) (int index) = { go, stop }; // Logic Cycle | |
| void recurse(const int i, const int kill_num) { | |
| recurse(LC[!(i % kill_num)](i), kill_num); | |
| } | |
| int main(const int argc, const char *argv[]) { | |
| recurse(1, atoi(argv[1])); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment