lbordonal / 02-push_swap

This project will make you sort data on a stack, with a limited set of instructions, using the lowest possible number of actions. To succeed you’ll have to manipulate various types of algorithms and choose the most appropriate solution (out of many) for an optimized data sorting.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

This repository contains code developed at 42 Porto for push_swap Project, from 03/01/2023 to 13/04/2023.

📓 Subject

Click here for the subject of this project.

💻 Usage

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

🏅 Mandatory Part

push_swap Rules:

The program is only allowed two stacks to work with, stack A and stack B. All the numbers are initially added to stack A, and B is empty.

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 and sb 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 and rb 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 and rrb at the same time.

Evaluation:

  • 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

Sort Algorithms:

  • 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 with ft_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.

About

This project will make you sort data on a stack, with a limited set of instructions, using the lowest possible number of actions. To succeed you’ll have to manipulate various types of algorithms and choose the most appropriate solution (out of many) for an optimized data sorting.

License:Other


Languages

Language:C 96.9%Language:Makefile 3.1%