| 1 |
/* guess.c — Number guessing game for Pactor64 */ |
| 2 |
#include "libc.h" |
| 3 |
|
| 4 |
/* Simple pseudo-random number generator */ |
| 5 |
static unsigned long rng_state = 12345; |
| 6 |
static unsigned long rng_next(void) { |
| 7 |
rng_state = rng_state * 6364136223846793005ULL + 1442695040888963407ULL; |
| 8 |
return rng_state; |
| 9 |
} |
| 10 |
|
| 11 |
int main(int argc, char **argv) { |
| 12 |
printf("=== Number Guessing Game ===\n\n"); |
| 13 |
printf("I'm thinking of a number between 1 and 100.\n"); |
| 14 |
printf("The Pactor64 RNG will pick it for you.\n\n"); |
| 15 |
|
| 16 |
int secret = (rng_next() % 100) + 1; |
| 17 |
int guesses[] = {50, 25, 75, 37, 62, 12, 87, 6}; |
| 18 |
int num_guesses = sizeof(guesses) / sizeof(guesses[0]); |
| 19 |
|
| 20 |
printf("Secret number: %d\n\n", secret); |
| 21 |
|
| 22 |
int found = 0; |
| 23 |
for (int i = 0; i < num_guesses && !found; i++) { |
| 24 |
int guess = guesses[i]; |
| 25 |
printf(" Guess %d: %d ", i + 1, guess); |
| 26 |
if (guess == secret) { |
| 27 |
printf("-> CORRECT! Found in %d guesses!\n", i + 1); |
| 28 |
found = 1; |
| 29 |
} else if (guess < secret) { |
| 30 |
printf("-> Too low\n"); |
| 31 |
} else { |
| 32 |
printf("-> Too high\n"); |
| 33 |
} |
| 34 |
} |
| 35 |
|
| 36 |
if (!found) |
| 37 |
printf("\n Not found in %d guesses. The number was %d.\n", num_guesses, secret); |
| 38 |
|
| 39 |
printf("\n=== Statistics ===\n"); |
| 40 |
printf(" RNG state: %lx\n", rng_state); |
| 41 |
printf(" Random numbers: "); |
| 42 |
for (int i = 0; i < 5; i++) |
| 43 |
printf("%ld ", rng_next() % 1000); |
| 44 |
printf("\n\nDone!\n"); |
| 45 |
return 0; |
| 46 |
} |
| 47 |
|