Skip to content

Instantly share code, notes, and snippets.

@maksadbek
Created August 17, 2019 19:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save maksadbek/7eb26bc4d98c9c1f4f748f2f46eb9aad to your computer and use it in GitHub Desktop.
Save maksadbek/7eb26bc4d98c9c1f4f748f2f46eb9aad to your computer and use it in GitHub Desktop.
#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