Created
February 17, 2019 12:42
-
-
Save padawin/b5a5e3158487fab6e246441727aa91b6 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <string.h> | |
#include <stdio.h> | |
// To solve https://www.instagram.com/p/Bt5v_YrlDhz/ | |
const char* alphabet[26] = { | |
"2.-", | |
"4-...", | |
"4-.-.", | |
"3-..", | |
"1.", | |
"4..-.", | |
"3--.", | |
"4....", | |
"2..", | |
"4.---", | |
"3-.-", | |
"4.-..", | |
"2--", | |
"2-.", | |
"3---", | |
"4.--.", | |
"4--.-", | |
"3.-.", | |
"3...", | |
"1-", | |
"3..-", | |
"4...-", | |
"3.--", | |
"4-..-", | |
"4-.--", | |
"4--.." | |
}; | |
void lookForWord(const char* input, char output[14], int curChar); | |
int main() { | |
const char* input = "....-.-..-..-"; | |
char output[14] = ""; | |
lookForWord(input, output, 0); | |
return 0; | |
} | |
void lookForWord(const char* input, char output[14], int curChar) { | |
if (*input == '\0') { | |
output[curChar] = '\0'; | |
printf("%s\n", output); | |
return; | |
} | |
for (char letter = 0; letter < 26; ++letter) { | |
if (strstr(input, alphabet[letter]+1) == input) { | |
output[curChar] = 'a' + letter; | |
lookForWord(input + *alphabet[letter] - '0', output, curChar + 1); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment