Gray code
(math/gray-code.hpp)
- View this file on GitHub
- Last update: 2020-12-05 07:59:51+09:00
- Include:
#include "math/gray-code.hpp"
Verified with
Code
#pragma once
vector<int> gray_code(int n) {
vector<int> ret(1 << n);
for (int i = 0; i < (int)ret.size(); i++) ret[i] = i ^ (i >> 1);
return ret;
};
/**
* @brief Gray code
*/
#line 2 "math/gray-code.hpp"
vector<int> gray_code(int n) {
vector<int> ret(1 << n);
for (int i = 0; i < (int)ret.size(); i++) ret[i] = i ^ (i >> 1);
return ret;
};
/**
* @brief Gray code
*/