This repository contains code developed at 42 Porto for push_swap Project, from 03/01/2023 to 13/04/2023.
Click here for the subject of this project.1- Clone this repository:
git clone https://github.com/lbordonal/02-push_swap.git
2- Navigate to push_swap folder:
cd 02-push_swap/push_swap/
3- Run with make:
make
4- Run push_swap with:
./push_swap number_1 number_2 ...
or ARG="number_1 number_2 ..."; ./push_swap $ARG
5- If you want to use the tester, run with:
ARG="number_1 number_2 ..."; ./push_swap $ARG | ./checker_linux $ARG
6- If you want to see how many moves it takes to sort, run with:
ARG="number_1 number_2 ..."; ./push_swap $ARG | wc -l
Moves:
pa
(push A): Take the first element at the top of B and put it at the top of A. Do nothing if B is empty.pb
(push B): Take the first element at the top of A and put it at the top of B. Do nothing if A is empty.sa
(swap A): Swap the first 2 elements at the top of stack A. Do nothing if there is only one or no elements.sb
(swap B): Swap the first 2 elements at the top of stack B. Do nothing if there is only one or no elements.ss
:sa
andsb
at the same time.ra
(rotate A): Shift all elements of stack A up by 1. The first element becomes the last one.rb
(rotate B): Shift all elements of stack B up by 1. The first element becomes the last one.rr
:ra
andrb
at the same time.rra
(reverse rotate A): Shift all elements of stack A down by 1. The last element becomes the first one.rrb
(reverse rotate B): Shift all elements of stack b down by 1. The last element becomes the first one.rrr
:rra
andrrb
at the same time.
-
Sorting 3 values: no more than 3 moves.
-
Sorting 5 values: no more than 12 moves.
-
Sorting 100 values: grade from 1 to 5 points depending on the number of moves:
- 5 points for less than 700
- 4 points for less than 900
- 3 points for less than 1100
- 2 points for less than 1300
- 1 point for less than 1500
-
Sorting 500 values: grade from 1 to 5 points depending on the number of moves:
- 5 points for less than 5500
- 4 points for less than 7000
- 3 points for less than 8500
- 2 points for less than 10000
- 1 point for less than 11500
- Sorting 3 values:
ft_sort_three
→ brute force, no more than 6 possible combinations to sort 3 numbers. - Sorting 5 values:
ft_sort_five
→ search for the minimum and the maximum values in stack A, push it to stack B → sort stack A withft_sort_three
→ push to stack A the elements in stack B, inserting them in the correct position in stack A. - Sorting less than 60 values:
ft_crazy_sort
→ find the lowest element in stack A and push it to stack B → do it again until stack A has only one element → pushback to stack A all the elements from stack B. - Sorting more than 60 values:
ft_sort
→ Radix sort.
This work is published under the terms of 42 Unlicense.