This project is the first project about algorithm in 42 School.
Nota: 84/100 ✔️
This project is inspired by the Tower of Hanoi, which involves moving a stack of disks from one rod to another, following these rules:
- Only one disk can be moved at a time.
- A disk can only be moved if it is the topmost disk.
- No disk may be placed on top of a smaller disk.
The goal is to transfer the entire stack to another rod, maintaining the original order.
Push Swap involves two stacks, where the first stack is filled with disorganized random numbers. The goal is to organize all the numbers in ascending order using specific movements in the fewest moves possible.
-
sa (swap a) - Swap the first 2 elements at the top of stack a.
-
sb (swap b) - Swap the first 2 elements at the top of stack b.
-
ss (swap a and b) - sa and sb at the same time.
-
pa (push a) - Take the first element at the top of b and put it at the top of a.
-
pb (push b) - Take the first element at the top of a and put it at the top of b.
-
ra (rotate a) - Shift up all elements of stack a by 1. The first element becomes the last.
-
rb (rotate b) - Shift up all elements of stack b by 1. The first element becomes the last.
-
rr (rotate a and b) - ra and rb at the same time.
-
rra (reverse rotate a) - Shift down all elements of stack a by 1. The last element becomes the first.
-
rrb (reverse rotate b) - Shift down all elements of stack b by 1. The last element becomes the first.
-
rrr (reverse rotate a and b) - rra and rrb at the same time.