Created
August 17, 2019 19:17
-
-
Save maksadbek/7eb26bc4d98c9c1f4f748f2f46eb9aad to your computer and use it in GitHub Desktop.
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 <bits/stdc++.h> | |
using namespace std; | |
void print_set(int s) { | |
printf("%d: ", s); | |
for(int i = 1; 0 < s; i++) { | |
if((s & 1) == 1) { | |
printf("%d, ", i); | |
} | |
s = s >> 1; | |
} | |
printf("\n"); | |
} | |
void gospers_hack(int k, int n) { | |
int set = (1 << k) - 1; | |
int limit = (1 << n); | |
while(set < limit) { | |
print_set(set); | |
int c = set & - set; | |
int r = set + c; | |
set = (((r ^ set) >> 2) / c) | r; | |
} | |
} | |
int main() { | |
// set of size 4, with limit of 2^5 | |
gospers_hack(4, 5); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment