This commit is contained in:
parent
f4c682bbea
commit
22e3eceb5d
1 changed files with 13 additions and 14 deletions
27
tennis.c
27
tennis.c
|
@ -174,6 +174,14 @@ int validate_entry(const char *entry) {
|
||||||
return decode_data(&code);
|
return decode_data(&code);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void print_code(code_t *code) {
|
||||||
|
for (int j = 0; j < 9; j++) {
|
||||||
|
int index = code->code[j];
|
||||||
|
printf("%c", lut[index][0]);
|
||||||
|
}
|
||||||
|
printf("\n");
|
||||||
|
}
|
||||||
|
|
||||||
static u64 prng_state = 1;
|
static u64 prng_state = 1;
|
||||||
static u32 prng() {
|
static u32 prng() {
|
||||||
prng_state = 3935559000370003845 * prng_state + 1;
|
prng_state = 3935559000370003845 * prng_state + 1;
|
||||||
|
@ -189,25 +197,19 @@ int bruteforce() { // with a fixed seed, this is useful for testing.
|
||||||
}
|
}
|
||||||
if (decode_data(&code)) {
|
if (decode_data(&code)) {
|
||||||
found++;
|
found++;
|
||||||
for (int j = 0; j < 9; j++) {
|
print_code(&code);
|
||||||
int index = code.code[j];
|
|
||||||
printf("%c", lut[index][0]);
|
|
||||||
}
|
|
||||||
printf("\n");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifndef TENNIS_NO_MAIN
|
||||||
int main(int argc, char **argv) {
|
int main(int argc, char **argv) {
|
||||||
if (argc == 1) {
|
if (argc == 1) {
|
||||||
// self-test with codes known before this program was written.
|
// self-test with codes known before this program was written.
|
||||||
#define TEST(entry) if (!validate_entry(entry)) return -1
|
#define TEST(entry) if (!validate_entry(entry)) return -1
|
||||||
TEST("48HWOR482");
|
TEST("48HWOR482");
|
||||||
TEST("5G3LTQ5GN");
|
TEST("5G3LTQ5GN");
|
||||||
//TEST("5PURGR5PM");
|
|
||||||
//TEST("6PJEGRGP5");
|
|
||||||
//TEST("8GYUHR86F");
|
|
||||||
TEST("A3W5KQA3C");
|
TEST("A3W5KQA3C");
|
||||||
TEST("ARM6JQARU");
|
TEST("ARM6JQARU");
|
||||||
TEST("E880MPE8K");
|
TEST("E880MPE8K");
|
||||||
|
@ -234,7 +236,6 @@ int main(int argc, char **argv) {
|
||||||
TEST("WQJEGRWQ5");
|
TEST("WQJEGRWQ5");
|
||||||
TEST("WRWQARWRC");
|
TEST("WRWQARWRC");
|
||||||
TEST("YQJEGRYQ5");
|
TEST("YQJEGRYQ5");
|
||||||
//TEST("ZKZLZKNNR");
|
|
||||||
#undef TEST
|
#undef TEST
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -246,6 +247,7 @@ int main(int argc, char **argv) {
|
||||||
for (int i = 1; i < argc; i++) {
|
for (int i = 1; i < argc; i++) {
|
||||||
const char *arg = argv[i];
|
const char *arg = argv[i];
|
||||||
if (strlen(arg) == 9) {
|
if (strlen(arg) == 9) {
|
||||||
|
//if (validate_entry(arg)) printf("%s\n", arg);
|
||||||
invalid_count += !validate_entry(arg);
|
invalid_count += !validate_entry(arg);
|
||||||
} else if (!strcmp(arg, "bruteforce")) {
|
} else if (!strcmp(arg, "bruteforce")) {
|
||||||
invalid_count += !bruteforce();
|
invalid_count += !bruteforce();
|
||||||
|
@ -257,11 +259,7 @@ int main(int argc, char **argv) {
|
||||||
if (code_i >= 7) {
|
if (code_i >= 7) {
|
||||||
code_i = 0;
|
code_i = 0;
|
||||||
if (encode_data(&code)) {
|
if (encode_data(&code)) {
|
||||||
for (int j = 0; j < 9; j++) {
|
print_code(&code);
|
||||||
int index = code.code[j];
|
|
||||||
printf("%c", lut[index][0]);
|
|
||||||
}
|
|
||||||
printf("\n");
|
|
||||||
} else {
|
} else {
|
||||||
invalid_count++;
|
invalid_count++;
|
||||||
}
|
}
|
||||||
|
@ -270,3 +268,4 @@ int main(int argc, char **argv) {
|
||||||
}
|
}
|
||||||
return invalid_count;
|
return invalid_count;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
Loading…
Reference in a new issue