Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // I misunderstood the reference manual. I had to tweak the program to fix it.
- // Module solver for Needy Knob (Keep Talking and Nobody Explodes)
- // Call without arguments for usage help
- #include <stdio.h>
- #include <string.h>
- #include <stdlib.h>
- #define SEQLEN (13)
- #define HAS_SUBSTR(haystack, needle) \
- ( strstr( (haystack), (needle) ) != NULL \
- || strstr( (haystack) + SEQLEN, (needle) ) != NULL )
- enum dir { UP, RIGHT, DOWN, LEFT, END };
- char *data[END] = {
- "001011111101\000101010011011",
- "101111111010\000101100111010",
- "011001111101\000101010010001",
- "000010100111\000000010000110"
- };
- void
- usage(void)
- {
- puts("Usage: needyknob <string of [01]>");
- puts("Enter enough digits such that only one match is found\n");
- puts("1 2");
- puts("XXX XXX");
- puts("3 4");
- puts("XXX XXX\n");
- puts("Protip 1: you only need the first 9 digits.");
- puts(" 1 2");
- puts("[XXX XXX]");
- puts(" 3 4");
- puts("[XXX] ...\n");
- puts("Protip 2: If the defuser is having trouble understanding the order, try using the DONT DEAD OPEN INSIDE meme as an example.");
- puts("I.e. you don't want 'DONT DEAD OPEN INSIDE'; you want 'DONT OPEN DEAD INSIDE', or rather, 'DONT OPEN DEAD'.");
- exit(1);
- }
- int
- main(int argc, char **argv)
- {
- int nmatches = 0;
- int matches[END] = {0};
- if(argv[1] == NULL)
- usage();
- if(HAS_SUBSTR(data[UP], argv[1])){
- nmatches++;
- matches[UP] = 1;
- }
- if(HAS_SUBSTR(data[RIGHT], argv[1])){
- nmatches++;
- matches[RIGHT] = 1;
- }
- if(HAS_SUBSTR(data[DOWN], argv[1])){
- nmatches++;
- matches[DOWN] = 1;
- }
- if(HAS_SUBSTR(data[LEFT], argv[1])){
- nmatches++;
- matches[LEFT] = 1;
- }
- if(nmatches == 0)
- puts("[!] No matches found. Double check what you typed.");
- if(nmatches > 1)
- puts("[!] Found multiple matches. Need more digits.");
- matches[UP] && puts("Up.");
- matches[RIGHT] && puts("Right.");
- matches[DOWN] && puts("Down.");
- matches[LEFT] && puts("Left.");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement