Advertisement
B1KMusic

KTaNE Module Solver: Needy Knob (correction)

Jul 4th, 2018
249
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.13 KB | None | 0 0
  1. // I misunderstood the reference manual. I had to tweak the program to fix it.
  2. // Module solver for Needy Knob (Keep Talking and Nobody Explodes)
  3. // Call without arguments for usage help
  4.  
  5. #include <stdio.h>
  6. #include <string.h>
  7. #include <stdlib.h>
  8.  
  9. #define SEQLEN (13)
  10.  
  11. #define HAS_SUBSTR(haystack, needle) \
  12.     (  strstr( (haystack), (needle) ) != NULL \
  13.     || strstr( (haystack) + SEQLEN, (needle) ) != NULL )
  14.  
  15. enum dir { UP, RIGHT, DOWN, LEFT, END };
  16.  
  17. char *data[END] = {
  18.     "001011111101\000101010011011",
  19.     "101111111010\000101100111010",
  20.     "011001111101\000101010010001",
  21.     "000010100111\000000010000110"
  22. };
  23.  
  24. void
  25. usage(void)
  26. {
  27.     puts("Usage: needyknob <string of [01]>");
  28.     puts("Enter enough digits such that only one match is found\n");
  29.     puts("1   2");
  30.     puts("XXX XXX");
  31.     puts("3   4");
  32.     puts("XXX XXX\n");
  33.     puts("Protip 1: you only need the first 9 digits.");
  34.     puts(" 1   2");
  35.     puts("[XXX XXX]");
  36.     puts(" 3    4");
  37.     puts("[XXX] ...\n");
  38.     puts("Protip 2: If the defuser is having trouble understanding the order, try using the DONT DEAD OPEN INSIDE meme as an example.");
  39.     puts("I.e. you don't want 'DONT DEAD OPEN INSIDE'; you want 'DONT OPEN DEAD INSIDE', or rather, 'DONT OPEN DEAD'.");
  40.     exit(1);
  41. }
  42.  
  43. int
  44. main(int argc, char **argv)
  45. {
  46.     int nmatches = 0;
  47.     int matches[END] = {0};
  48.  
  49.     if(argv[1] == NULL)
  50.         usage();
  51.  
  52.     if(HAS_SUBSTR(data[UP], argv[1])){
  53.         nmatches++;
  54.         matches[UP] = 1;
  55.     }
  56.  
  57.     if(HAS_SUBSTR(data[RIGHT], argv[1])){
  58.         nmatches++;
  59.         matches[RIGHT] = 1;
  60.     }
  61.  
  62.     if(HAS_SUBSTR(data[DOWN], argv[1])){
  63.         nmatches++;
  64.         matches[DOWN] = 1;
  65.     }
  66.  
  67.     if(HAS_SUBSTR(data[LEFT], argv[1])){
  68.         nmatches++;
  69.         matches[LEFT] = 1;
  70.     }
  71.  
  72.     if(nmatches == 0)
  73.         puts("[!] No matches found. Double check what you typed.");
  74.  
  75.     if(nmatches > 1)
  76.         puts("[!] Found multiple matches. Need more digits.");
  77.  
  78.     matches[UP] && puts("Up.");
  79.     matches[RIGHT] && puts("Right.");
  80.     matches[DOWN] && puts("Down.");
  81.     matches[LEFT] && puts("Left.");
  82.  
  83.     return 0;
  84. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement