push_swap

Description

Push_swap is a function that sorts in ascending order a stack (stack a) using a temporal stack (stack b).

Allowed Operations

  • sa: Swaps the first two elements at the top of stack a.
  • sb: Swaps the first two elements at the top of stack b.
  • ss: Does sa and sb at the same time.
  • pa: If stack b is not empty, puts the first element at the top into stack a.
  • pb: If stack a is not empty, puts the first element at the top into stack b.
  • ra: Shifts up all elements of stack a by 1. So the first element becomes the last one.
  • rb: Shifts up all elements of stack b by 1. So the first element becomes the last one.
  • rr: Does ra and rb at the same time.
  • rra: Shifts down all elements of stack a by 1. So the last element becomes the first one.
  • rrb: Shifts down all elements of stack b by 1. So the last element becomes the first one.
  • rrr: Does rra and rrb at the same time.

The goal is to sort the stack in the lowest amount of operations possible.

Bonus

I have to create a function that has to replicate the behaviour of the given checker for push_swap.

Allowed Functions

Progress

If you want to check my progress as a student in 42 Málaga check out my main repository!