Last active
May 11, 2018 09:58
-
-
Save hanachin/3e2f9034e0fe382f019e55de4c6b016b to your computer and use it in GitHub Desktop.
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
#define __environment _CbC_environment | |
#define __return _CbC_return | |
#include <stdio.h> | |
typedef __code(*main_ret_code_t)(int, void *env); | |
__code fizzbuzz(int n, int max, main_ret_code_t ret, void *env); | |
__code fizz(int n, int max, main_ret_code_t ret, void *env); | |
__code buzz(int n, int max, const char *fizz, main_ret_code_t ret, void *env); | |
__code print_fizzbuzz(int n, int max, const char *fizz, const char *buzz, main_ret_code_t ret, void *env); | |
int main(void){ | |
goto fizzbuzz(1, 100, __return, __environment); | |
} | |
__code fizzbuzz(int n, int max, main_ret_code_t ret, void *env) { | |
if (n > max) goto ret(0, env); | |
goto fizz(n, max, ret, env); | |
} | |
__code fizz(int n, int max, main_ret_code_t ret, void *env) { | |
if (n % 3 == 0) { | |
goto buzz(n, max, "Fizz", ret, env); | |
} else { | |
goto buzz(n, max, "", ret, env); | |
} | |
} | |
__code buzz(int n, int max, const char *fizz, main_ret_code_t ret, void *env) { | |
if (n % 5 == 0) { | |
goto print_fizzbuzz(n, max, fizz, "Buzz", ret, env); | |
} else { | |
goto print_fizzbuzz(n, max, fizz, "", ret, env); | |
} | |
} | |
__code print_fizzbuzz(int n, int max, const char *fizz, const char *buzz, main_ret_code_t ret, void *env) { | |
if (*fizz || *buzz) { | |
printf("%s%s\n", fizz, buzz); | |
} else { | |
printf("%d\n", n); | |
} | |
goto fizzbuzz(n + 1, max, ret, env); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment