Last active
November 24, 2016 01:25
-
-
Save alexanderankin/cec66abfdd5b4b8513c0688c40023c4d to your computer and use it in GitHub Desktop.
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
typedef int boolean_t; | |
boolean_t (*status_checker_function)(void); | |
int change_bulb_required_engineers_recur(status_checker_function); | |
int change_bulb_required_engineers_recur(status_checker_function testbulb) | |
{ | |
return _change_bulb_required_engineers_recur(testbulb, 0); | |
} | |
/** | |
* We are not at the mercy of a microcontroller or compiler w/o tail-call-O | |
*/ | |
int _change_bulb_required_engineers_recur(status_checker_function, int); | |
int _change_bulb_required_engineers_recur(status_checker_function testbulb, int num_engineers_already) | |
{ | |
return testbulb() ? num_engineers : _change_bulb_required_engineers(testbulb, num_engineers + 1); | |
} | |
int change_bulb_required_engineers(status_checker_function); | |
int change_bulb_required_engineers(status_checker_function testbulb) | |
{ | |
int counter = 0; | |
while ( !testbulb() ) | |
counter++; | |
return counter; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment