started at . submit by
too long have programs been made that make user guess some number. it's time to switch the roles up - now the user will think of an integer between 1 and 100 (inclusive), and your program will guess the number!
while any language is allowed, a number of standard interfaces are proposed. in functional languages, such as C and Python, one could define a procedure that accepts a closure as an argument, which the procedure calls with an integer to submit its guesses, and the closure returns, as an integer, the result: -1 if the guess is too low, 1 if the guess is too high, or 0 if the guess is spot on. closure can be called multiple times, until a guess is found. the sigmature would look like this in C:
void entry(int (*submit)(int, void*), void *data) {
int result = submit(42, data);
// ...
}
or in Python:
def entry(submit):
result = submit(42)
// ...
similar pattern should be adaptable to other languages. if not, there is an alternate interface. instead, you can communicate with the user via the standard IO streams. simply print the guess on its own line using ASCII digits to stdout, then read a line from stdin: it will spell "LOW" (no quotes) if your guess is too low, "HIGH" if your guess is too high, "WIN" if your guess is spot on. rinse and repeat until WIN.
if neither standard interface works for your language or you just don't like to implement it, you are free to invent your own interface.
your challenge, given a procedure, write a program that guesses a number between 1 and 100. any language is allowed, there is an API.
2 entries have been received so far.