Created
October 7, 2017 19:19
-
-
Save shreevatsa/82ef6bc5a513dea5b51436253793c2ff to your computer and use it in GitHub Desktop.
Brute-force program for cops-and-robbers 144601
This file contains hidden or 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 <iostream> | |
#include <set> | |
typedef long long Int; | |
Int candidates_a[1<<17]; int length_a = 0; std::string full_a = "74837258394056219"; | |
Int candidates_b[1<<9]; int length_b = 0; std::string full_b = "268435455"; | |
Int candidates_c[1<<9]; int length_c = 0; std::string full_c = "124038877"; | |
void subset_ints(std::string full, Int where[], int* length) { | |
int n = full.size(); | |
int N = 1 << full.size(); | |
for (int s = 0; s < N; ++s) { | |
Int val = 0; | |
for (int i = 0; i < n; ++i) { | |
if ((s & (1 << i))) val = val * 10 + (full[i] - '0'); | |
} | |
where[*length] = val; | |
++*length; | |
} | |
} | |
int main() { | |
subset_ints(full_a, candidates_a, &length_a); | |
subset_ints(full_b, candidates_b, &length_b); | |
subset_ints(full_c, candidates_c, &length_c); | |
std::set<Int> all_c(candidates_c, candidates_c + length_c); | |
for (int ia = 0; ia < length_a; ++ia) { | |
Int a = candidates_a[ia]; | |
for (int ib = 0; ib < length_b; ++ib) { | |
Int b = candidates_b[ib]; | |
int k = 35; | |
for (int x = 0; x < 35; ++x) k = (k * a) & b; | |
Int c = k ^ 21625674; | |
if (all_c.count(c)) { | |
std::cout << a << " " << b << " " << c << std::endl; | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
For this one: https://codegolf.stackexchange.com/a/144620/3845