/push_swap

A 42 Project

Primary LanguageC

push_swap

A 42 Cursus Project

Objectives

The project requires students to receive an unsorted arrangement of numbers and sort them in ascending order with a limited set of instructions.

Instruction Description
sa (swap a) swap the first two elements at top of Stack A
sb (swap b) swap the first two elements at top of Stack B
ss perform sa and sb simultaneously
pa (push a) take the first element of Stack B and place in top of Stack A
do nothing if B is empty
pb (push b) take the first element of Stack A and place in top of Stack B
do nothing if A is empty
ra (rotate a) move all elements up in Stack A
rb (rotate b) move all elements up in Stack B
rr perform ra and rb simultaneously
rra (reverse rotate a) move all elements down in Stack A
rrb (reverse rotate b) move all elements down in Stack B
rrr perform rra and rrb simultaneously

Libft

Libft library is allowed in the project.

Result

Sorts 3 numbers in < 3 moves

Sorts 5 numbers in < 12 moves

Sorts 100 numbers in < 900 moves

Sorts 500 numbers in < 8500 moves

Screenshot 2022-04-14 182547

good enough

Early 2022 Version of push_swap

Does not include bonuses

Useful Resources

https://zainab-dnaya.medium.com/fastest-push-swap-algorithm-2f510028602b

https://medium.com/nerd-for-tech/push-swap-tutorial-fa746e6aba1e

https://medium.com/@jamierobertdawson/push-swap-the-least-amount-of-moves-with-two-stacks-d1e76a71789a

https://www.random.org/integer-sets/

https://github.com/laisarena/push_swap_tester