Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- void move(size_t n, size_t x, size_t y) {
- size_t z = 6 - x - y;
- if (n) {
- move(n - 1, x, z);
- std::cout << n << " " << x << " " << y << "\n";
- move(n - 1, z, y);
- }
- }
- void move_n_sort(size_t n, size_t x, size_t y) {
- size_t z = 6 - x - y;
- if (n) {
- if (n % 2) {
- move(n, x, 2);
- move_n_sort(n - 1, 2, 3);
- } else {
- move(n, x, 3);
- move_n_sort(n - 1, 3, 2);
- }
- }
- }
- int main() {
- size_t n;
- std::cin >> n;
- move_n_sort(n, 1, 3);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement