Advertisement
vlatkovski

SOTF Combinatorics MMO-B W9/H4

May 4th, 2018
310
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.73 KB | None | 0 0
  1. #include <iostream>
  2. #include <set>
  3. #include <bitset>
  4. using namespace std;
  5.  
  6. /*
  7.  
  8. This is a bruteforce solution to the following COMBINATORICS problem,
  9. intended to be solved purely mathematically.
  10.  
  11. "Plus and minus signs are arranged in a 4x4 table as shown below.
  12.  
  13.     + | + | - | +
  14.     + | + | + | +
  15.     + | + | + | +
  16.     + | + | + | +
  17.  
  18. It is permissible to reverse all the signs in one row, one column,
  19. or along any line parallel to a diagonal of the table (in particular,
  20. in any corner unit square). Does there exist a sequence of these
  21. operations leading to a table with only plus signs?"
  22.  
  23. */
  24.  
  25. set<int> all;
  26.  
  27. void f(int g) {
  28.     if (all.find(g) != all.end())
  29.         return;
  30.     all.insert(g);
  31.     //perform all possible operations
  32.     //f(g XOR mask), where each active bit in the mask
  33.     //signifies whether to flip the bit
  34.     f(g^0b1111000000000000);
  35.     f(g^0b0000111100000000);
  36.     f(g^0b0000000011110000);
  37.     f(g^0b0000000000001111);
  38.     f(g^0b1000100010001000);
  39.     f(g^0b0100010001000100);
  40.     f(g^0b0010001000100010);
  41.     f(g^0b0001000100010001);
  42.     f(g^0b1000010000100001);
  43.     f(g^0b0001001001001000);
  44.     f(g^0b0100001000010000);
  45.     f(g^0b0010000100000000);
  46.     f(g^0b0001000000000000);
  47.     f(g^0b0010010010000000);
  48.     f(g^0b0100100000000000);
  49.     f(g^0b1000000000000000);
  50.     f(g^0b0000000100100100);
  51.     f(g^0b0000000000010010);
  52.     f(g^0b0000000000000001);
  53.     f(g^0b0000100001000010);
  54.     f(g^0b0000000010000100);
  55.     f(g^0b0000000000001000);
  56. }
  57.  
  58. int main() {
  59.     int initial = 0b1101111111111111;
  60.     f(initial);
  61.  
  62.     cout << "Number of possible tables: " << all.size() << '\n';
  63.     bitset<16> best = *prev(all.end());
  64.     cout << "Closest table to all pluses: " << best << '\n';
  65. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement