-
-
Save letoh/abd31b473588138cea2e 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
// modified from b****'s implementation https://gist.github.com/anonymous/aaafa4bd4de9d1a8ffa0 | |
#include <stdio.h> | |
#include <stdlib.h> | |
#include <stdint.h> | |
#include <string.h> | |
#include <stdarg.h> | |
enum {n, y, d, o, r, e, m, s, _}; | |
int to_num(char hash[], ...) { | |
int n = 0; | |
char c; | |
va_list ap; | |
va_start(ap, hash); | |
while(_ != (c = (char) va_arg(ap, int))) | |
n = n * 10 + hash[c]; | |
va_end(ap); | |
return n; | |
} | |
int found(const char hash[], int p, const char c) | |
{ | |
while(++p != _) | |
if(hash[p] == c) return 1; | |
return 0; | |
} | |
int main() { | |
char smerodyn[_] = {0}; | |
uint32_t send, more, money; | |
char *f = smerodyn; | |
#define num(...) to_num(f, __VA_ARGS__, _) | |
for (f[s]=1; f[s]<=9; f[s]+=1) | |
for (f[m]=1; f[m]<=9; f[m]+=1) if (found(f, m, f[m])) continue; else | |
for (f[e]=0; f[e]<=9; f[e]+=1) if (found(f, e, f[e])) continue; else | |
for (f[r]=0; f[r]<=9; f[r]+=1) if (found(f, r, f[r])) continue; else | |
for (f[o]=0; f[o]<=9; f[o]+=1) if (found(f, o, f[o])) continue; else | |
for (f[d]=0; f[d]<=9; f[d]+=1) if (found(f, d, f[d])) continue; else | |
for (f[y]=0; f[y]<=9; f[y]+=1) if (found(f, y, f[y])) continue; else | |
for (f[n]=0; f[n]<=9; f[n]+=1) if (found(f, n, f[n])) continue; else { | |
send = num(s, e, n, d); | |
more = num(m, o, r, e); | |
money = num(m, o, n, e, y); | |
if (money == send + more) { | |
printf("match found: send=%d, more=%d, money=%d\n", send, more, money); | |
return 0; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment