Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- int next_num(int n) {
- if (n != 3) {
- return n + 1;
- }
- return 1;
- }
- void move(int n, int x, int y) {
- if (n > 1) {
- if (y == next_num(x)) {
- move(n - 1, x, y);
- move(n - 1, y, next_num(y));
- cout << n << " " << x << " " << y << endl;
- move(n - 1, next_num(y), x);
- move(n - 1, x, y);
- } else {
- move(n - 1, x, next_num(x));
- move(n - 1, next_num(x), y);
- cout << n << " " << x << " " << next_num(x) << endl;
- move(n - 1, y, x);
- cout << n << " " << next_num(x) << " " << y << endl;
- move(n - 1, x, next_num(x));
- move(n - 1, next_num(x), y);
- }
- } else {
- if (y == next_num(x)) {
- cout << 1 << " " << x << " " << y << endl;
- } else {
- cout << 1 << " " << x << " " << next_num(x) << endl;
- cout << 1 << " " << next_num(x) << " " << y << endl;
- }
- }
- }
- int main() {
- int n;
- cin >> n;
- move(n, 1, 3);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement