summaryrefslogtreecommitdiff
path: root/introductory_problems/gray_code.cpp
blob: 9911cd437d2fc1861e04685b5a43fe88aad478fd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
// 2205. Gray Code
#include <bits/stdc++.h>
using namespace std;

static int n;
const int max_n = 16;
static bool a[max_n + 1];

void print(void) {
  for (int i = n; i; i--)
    printf("%d", a[i]);
  printf("\n");
}

int main() {
  scanf("%d", &n);
  print();
  for (int i = 1; i < 1 << n; i++) {
    int lsb = __builtin_ffs(i);
    a[lsb] ^= 1;
    print();
  }
}