Advertisement
achulkov2

Untitled

Feb 24th, 2018
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.59 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. void move(size_t n, size_t x, size_t y) {
  4. size_t z = 6 - x - y;
  5. if (n) {
  6. move(n - 1, x, z);
  7. std::cout << n << " " << x << " " << y << "\n";
  8. move(n - 1, z, y);
  9. }
  10. }
  11.  
  12. void move_n_sort(size_t n, size_t x, size_t y) {
  13. size_t z = 6 - x - y;
  14. if (n) {
  15. if (n % 2) {
  16. move(n, x, 2);
  17. move_n_sort(n - 1, 2, 3);
  18. } else {
  19. move(n, x, 3);
  20. move_n_sort(n - 1, 3, 2);
  21. }
  22. }
  23. }
  24.  
  25. int main() {
  26. size_t n;
  27. std::cin >> n;
  28. move_n_sort(n, 1, 3);
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement