Last active
January 11, 2021 18:41
-
-
Save wm3/a198bb005a7880bcd5cf5ac6fe4d77ab to your computer and use it in GitHub Desktop.
FDCAJHxIBCFEH=FBAECIIJEGIH
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
// https://twitter.com/miharasan/status/1348654370921934849?s=20 | |
#include <stdio.h> | |
long v[] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }; | |
long val(char alpha) { | |
return v[alpha - 'A']; | |
} | |
long vals(char *text) { | |
long res = 0; | |
for (int i = 0; text[i] != '\0'; ++i) { | |
res = res * 10 + val(text[i]); | |
} | |
return res; | |
} | |
void iterate(int o) { | |
if (o == 0) { | |
long v1 = vals("FDCAJH"); | |
long v2 = vals("IBCFEH"); | |
long v3 = vals("FBAECIIJEGIH"); | |
if (v1 * v2 == v3) { | |
printf("%ld*%ld=%ld\n", v1, v2, v3); | |
} | |
} else { | |
long ov = v[o - 1]; | |
for (int i = 0; i < o; ++i) { | |
long nv = v[i]; | |
v[i] = ov; | |
v[o - 1] = nv; | |
iterate(o - 1); | |
v[i] = nv; | |
v[o - 1] = ov; | |
} | |
} | |
} | |
int main(void) { | |
iterate(10); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment