Files
ioccc/2024/burton/gen.c
T
Landon Curt Noll 09750f8899 release winning entries of IOCCC28 under the year 2024
Congratulations to:

* 2024/anders - Prize in sound coding - layered music generator
* 2024/burton - Prize in pentagrammatology - wordle hard mode solver
* 2024/cable1 - Prize in bot talk - LLM inference engine
* 2024/cable2 - Prize in murky waters - salmon recipe
* 2024/carlini - Prize in perfect timing - Intel 4004 emulation
* 2024/codemeow - Prize in tray planting - bonsai generator
* 2024/endoh1 - Prize in patient pointillism - slow ray tracer in CPP
* 2024/endoh2 - Prize in solid body physics - rotating rigid body simulation
* 2024/ferguson1 - Prize in diabolical logistics - Oregon trail pact with the devil
* 2024/ferguson2 - Prize in yil-tas - Navajo code talker translator
* 2024/howe - Nice accent eh-ward - mini vi
* 2024/kramer - Prize in linguistic arithmetic - natural language numerical calculator
* 2024/kurdyukov1 - Prize in phased periodicity - phase of the Moon
* 2024/kurdyukov2 - Prize in art restoration - JPEG artifact removal
* 2024/kurdyukov3 - Prize in virtual quietus - gaming VM and doom
* 2024/kurdyukov4 - Prize in embiggening - encode without literals
* 2024/maffiodo - Prize in creative interpretation - Jav\*script interpreter
* 2024/mills - Prize in ℤ₃ - Infocom v3 story interpreter
* 2024/stedolan - Best one liner - icon from MD5
* 2024/straadt - Prize in imitative rebooting - OpenRISC CPU and Linux
* 2024/tmarrec - Prize in cyclonic coding - 3D tornado simulation
* 2024/tompng - Prize in quasi bijection - vortex encryptor decryptor
* 2024/weaver - Sur prize - rickroll

Ran `make update` to perform the above.
 	new file:   2024/burton/.entry.json
2025-08-02 14:43:07 -07:00

87 lines
1.7 KiB
C

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <time.h>
/*
* Wordle generator - text mode
* This program works in coordination with the obfuscated code
* to allow one to play more rapidly (e.g. test the algorithm)
* or just to play along in text mode.
*
* This version is a pale imitation of the Real Wordle(tm).
* If you want to get the real experience, please visit:
*
* https://www.nytimes.com/games/wordle/index.html
*/
static int
check(char *w, char *target)
{
printf("%.5s ", w);
for (int i = 0; i < 5; ++i) {
if (w[i] == target[i])
putchar('g');
else if (memchr(target, w[i], 5))
putchar('y');
else
putchar('b');
}
putchar('\n');
fflush(stdout);
return memcmp(w, target, 5) == 0;
}
int
main(int ac, char **av)
{
char words[78557][5];
char buf[100];
int cnt = 0, win = 0;
int nguesses = 6;
if (ac < 2) {
fprintf(stderr, "usage: %s dict [target]\n", av[0]);
return 1;
}
if (getenv("GUESSES")) {
nguesses = atoi(getenv("GUESSES"));
// fprintf(stderr, "using %d guesses\n", nguesses);
}
FILE *fp = fopen(av[1], "r");
if (!fp) {
perror(av[1]);
exit(1);
}
while (fgets(buf, sizeof buf, fp)) {
if (buf[5] != '\n')
continue;
memcpy(words[cnt++], buf, 5);
}
fclose(fp);
srandom(time(0) ^ getpid());
char *target = ac == 3 ? av[2] : words[random() % cnt];
getenv("CHEAT") && printf("target: %.5s\n", target);
int i;
for (i = 0; i < nguesses; ) {
printf("? "); fflush(stdout);
if (!fgets(buf, sizeof buf, stdin))
break;
if (buf[5] != '\n') {
printf("you must enter 5 letters\n");
continue;
}
++i;
if ((win = check(buf, target)))
break;
}
printf("%c %d %s: %.5s\n", win ? 'y' : 'n', i, win ? "good" : "lose", target);
return 0;
}