Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Brute-force program for cops-and-robbers 144601
#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;
}
}
}
}
@shreevatsa

This comment has been minimized.

Copy link
Owner Author

@shreevatsa shreevatsa commented Oct 7, 2017

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment