Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <set>
- #include <bitset>
- using namespace std;
- /*
- This is a bruteforce solution to the following COMBINATORICS problem,
- intended to be solved purely mathematically.
- "Plus and minus signs are arranged in a 4x4 table as shown below.
- + | + | - | +
- + | + | + | +
- + | + | + | +
- + | + | + | +
- It is permissible to reverse all the signs in one row, one column,
- or along any line parallel to a diagonal of the table (in particular,
- in any corner unit square). Does there exist a sequence of these
- operations leading to a table with only plus signs?"
- */
- set<int> all;
- void f(int g) {
- if (all.find(g) != all.end())
- return;
- all.insert(g);
- //perform all possible operations
- //f(g XOR mask), where each active bit in the mask
- //signifies whether to flip the bit
- f(g^0b1111000000000000);
- f(g^0b0000111100000000);
- f(g^0b0000000011110000);
- f(g^0b0000000000001111);
- f(g^0b1000100010001000);
- f(g^0b0100010001000100);
- f(g^0b0010001000100010);
- f(g^0b0001000100010001);
- f(g^0b1000010000100001);
- f(g^0b0001001001001000);
- f(g^0b0100001000010000);
- f(g^0b0010000100000000);
- f(g^0b0001000000000000);
- f(g^0b0010010010000000);
- f(g^0b0100100000000000);
- f(g^0b1000000000000000);
- f(g^0b0000000100100100);
- f(g^0b0000000000010010);
- f(g^0b0000000000000001);
- f(g^0b0000100001000010);
- f(g^0b0000000010000100);
- f(g^0b0000000000001000);
- }
- int main() {
- int initial = 0b1101111111111111;
- f(initial);
- cout << "Number of possible tables: " << all.size() << '\n';
- bitset<16> best = *prev(all.end());
- cout << "Closest table to all pluses: " << best << '\n';
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement