diff options
Diffstat (limited to 'challenge-070/lubos-kolouch/cpp')
| -rw-r--r-- | challenge-070/lubos-kolouch/cpp/ch-2.cpp | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/challenge-070/lubos-kolouch/cpp/ch-2.cpp b/challenge-070/lubos-kolouch/cpp/ch-2.cpp new file mode 100644 index 0000000000..2e2bd18cdd --- /dev/null +++ b/challenge-070/lubos-kolouch/cpp/ch-2.cpp @@ -0,0 +1,23 @@ +#include <iostream> +#include <vector> +#include <string> +#include <algorithm> + +int main() { + int N = 4; + std::vector<std::string> grayCode = {"0", "1"}; + + for (int i = 2; i <= N; i++) { + std::vector<std::string> revGrayCode(grayCode.rbegin(), grayCode.rend()); + for (auto &x : grayCode) x = '0' + x; + for (auto &x : revGrayCode) x = '1' + x; + grayCode.insert(grayCode.end(), revGrayCode.begin(), revGrayCode.end()); + } + + for (const auto &x : grayCode) { + std::cout << std::stoi(x, nullptr, 2) << ' '; + } + std::cout << '\n'; + + return 0; +} |
