Skip to content

Instantly share code, notes, and snippets.

@padawin
Created February 17, 2019 12:42
Show Gist options
  • Save padawin/b5a5e3158487fab6e246441727aa91b6 to your computer and use it in GitHub Desktop.
Save padawin/b5a5e3158487fab6e246441727aa91b6 to your computer and use it in GitHub Desktop.
#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