Advertisement
Guest User

Untitled

a guest
Feb 22nd, 2018
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.11 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int next_num(int n) {
  5. if (n != 3) {
  6. return n + 1;
  7. }
  8. return 1;
  9. }
  10. void move(int n, int x, int y) {
  11. if (n > 1) {
  12. if (y == next_num(x)) {
  13. move(n - 1, x, y);
  14. move(n - 1, y, next_num(y));
  15. cout << n << " " << x << " " << y << endl;
  16. move(n - 1, next_num(y), x);
  17. move(n - 1, x, y);
  18. } else {
  19. move(n - 1, x, next_num(x));
  20. move(n - 1, next_num(x), y);
  21. cout << n << " " << x << " " << next_num(x) << endl;
  22. move(n - 1, y, x);
  23. cout << n << " " << next_num(x) << " " << y << endl;
  24. move(n - 1, x, next_num(x));
  25. move(n - 1, next_num(x), y);
  26. }
  27. } else {
  28. if (y == next_num(x)) {
  29. cout << 1 << " " << x << " " << y << endl;
  30. } else {
  31. cout << 1 << " " << x << " " << next_num(x) << endl;
  32. cout << 1 << " " << next_num(x) << " " << y << endl;
  33. }
  34. }
  35. }
  36. int main() {
  37. int n;
  38. cin >> n;
  39. move(n, 1, 3);
  40. return 0;
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement