First, we start with two stacks called A and B.
A is filled with some random integers (without duplicate) and B is empty.
We can perform certain instructions on these stacks, and the goal is to sort all these integers with the least instructions possible.
And here is the list of instructions that we can perform :
- 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 : 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 one.
- rb (rotate b): Shift up all elements of stack b by 1. The first element becomes the last one.
- rr : 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 one.
- rrb (reverse rotate b): Shift down all elements of stack b by 1. The last element becomes the first one.
- rrr : rra and rrb at the same time.
-
With 3 numbers, we need to sort it with not more than 3 instructions.
-
With 5 numbers, we need to sort it with not more than 12 instructions.
-
With 100 numbers, we can get
-
5 points if the size of the list of instructions is less than 700
-
4 points if the size of the list of instructions is less than 900
-
3 points if the size of the list of instructions is less than 1100
-
2 points if the size of the list of instructions is less than 1300
-
1 points if the size of the list of instructions is less than 1500
-
-
With 500 numbers, we can get
-
5 points if the size of the list of instructions is less than 5500
-
4 points if the size of the list of instructions is less than 7000
-
3 points if the size of the list of instructions is less than 8500
-
2 points if the size of the list of instructions is less than 10000
-
1 points if the size of the list of instructions is less than 11500
-
Decided to implement the stack by using a linked list.
Used the following tester:
https://medium.com/nerd-for-tech/push-swap-tutorial-fa746e6aba1e
https://medium.com/@ayogun/push-swap-c1f5d2d41e97
https://zainab-dnaya.medium.com/fastest-push-swap-algorithm-2f510028602b