{"id":22153179,"url":"https://github.com/dpetrosy/42-push-swap","last_synced_at":"2025-03-24T13:42:22.846Z","repository":{"id":225648994,"uuid":"766498796","full_name":"dpetrosy/42-Push-Swap","owner":"dpetrosy","description":"42 School Push_Swap - Algorithmic project on C","archived":false,"fork":false,"pushed_at":"2024-03-18T19:33:41.000Z","size":3032,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-01-29T18:46:40.032Z","etag":null,"topics":["42","42-cursus","42-push-swap","42born2code","42cursus","42projects","42pushswap","42school","42yerevan","algorithm","c","c-programming","push-swap","push-swap-42","pushswap","pushswap-42","pushswap42","sorting","sorting-algorithms","stack"],"latest_commit_sha":null,"homepage":"","language":"C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/dpetrosy.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-03-03T12:44:40.000Z","updated_at":"2024-03-18T13:15:59.000Z","dependencies_parsed_at":"2024-03-03T14:23:23.948Z","dependency_job_id":"ebf691c9-fdf7-4ea3-8b3f-64c76a58b928","html_url":"https://github.com/dpetrosy/42-Push-Swap","commit_stats":null,"previous_names":["dpetrosy/42-push-swap"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dpetrosy%2F42-Push-Swap","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dpetrosy%2F42-Push-Swap/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dpetrosy%2F42-Push-Swap/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dpetrosy%2F42-Push-Swap/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/dpetrosy","download_url":"https://codeload.github.com/dpetrosy/42-Push-Swap/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245283839,"owners_count":20590299,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["42","42-cursus","42-push-swap","42born2code","42cursus","42projects","42pushswap","42school","42yerevan","algorithm","c","c-programming","push-swap","push-swap-42","pushswap","pushswap-42","pushswap42","sorting","sorting-algorithms","stack"],"created_at":"2024-12-02T01:17:21.105Z","updated_at":"2025-03-24T13:42:22.823Z","avatar_url":"https://github.com/dpetrosy.png","language":"C","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003ca name=\"readme-top\"\u003e\u003c/a\u003e\n\u003cdiv align=\"center\"\u003e\n  \u003c!-- Logo --\u003e\n  \u003ca href=\"https://github.com/dpetrosy/42-Push-Swap\"\u003e\n  \u003cimg src=\"README_files/logo.png\" alt=\"Logo\" width=\"80\" height=\"80\"\u003e\n  \u003c/a\u003e\n\n  \u003c!-- Project Name --\u003e\n  \u003ch1\u003ePush-Swap Project\u003c/h1\u003e\n\n  \u003c!-- Short Description --\u003e\n  \u003cp align=\"center\"\u003e\n\t  \u003cb\u003e42 Yerevan Push-Swap\u003c/b\u003e\u003cbr\u003e\n\t  For further information about 42cursus and its projects, please refer to \u003ca href=\"https://github.com/dpetrosy/42cursus\"\u003e\u003cb\u003e42cursus repo\u003c/b\u003e\u003c/a\u003e.\n  \u003c/p\u003e\n\n  \u003c!-- Badges --\u003e\n  \u003cp\u003e\n    \u003cimg src=\"https://img.shields.io/badge/score-125%20%2F%20100-success?style=for-the-badge\" /\u003e\n    \u003cimg src=\"https://img.shields.io/github/repo-size/dpetrosy/42-Push-Swap?style=for-the-badge\u0026logo=github\"\u003e\n    \u003cimg src=\"https://img.shields.io/github/languages/count/dpetrosy/42-Push-Swap?style=for-the-badge\u0026logo=\" /\u003e\n    \u003cimg src=\"https://img.shields.io/github/languages/top/dpetrosy/42-Push-Swap?style=for-the-badge\" /\u003e\n    \u003cimg src=\"https://img.shields.io/github/last-commit/dpetrosy/42-Push-Swap?style=for-the-badge\" /\u003e\n  \u003c/p\u003e\n\n  \u003ch3\u003e\n      \u003ca href=\"#-about-project\"\u003e📜 About Project\u003c/a\u003e\n    \u003cspan\u003e · \u003c/span\u003e\n      \u003ca href=\"#-operations-list\"\u003e📑 Operations List\u003c/a\u003e\n    \u003cspan\u003e · \u003c/span\u003e\n\t  \u003ca href=\"#-algorithm\"\u003e🧮 Algorithm\u003c/a\u003e\n    \u003cspan\u003e · \u003c/span\u003e\n\t  \u003ca href=\"#-bonus-part\"\u003e🌟 Bonus Part\u003c/a\u003e\n    \u003cspan\u003e · \u003c/span\u003e\n      \u003ca href=\"#-usage\"\u003e👨‍💻 Usage\u003c/a\u003e\n  \u003c/h3\u003e\n\u003c/div\u003e\n\n---\n\n## 📜 About Project\n\n* This project will make you sort data on a stack, with a limited set of operations, using the lowest possible number of actions.\n\n* The Push_swap project is a very simple and highly effective algorithm project: data will need to be sorted.  \nYou have at your disposal a set of int values, 2 stacks and a set of operations to manipulate both stacks.  \n\n* The goal is to write a program in C called push_swap which calculates and displays on the standard output the operations, that sort the integers received as arguments.\n\n* The learning objectives of this project are rigor, use of C and use of basic algorithms. Especially looking at the complexity of these basic algorithms.\n\n* You are allowed to use the following functions: malloc, free, exit, write, read.\n\nFor detailed information, refer to the [**subject of this project**](README_files/push_swap_subject.pdf).\n\n\t🚀 TLDR: Given a set of integers, sort it using a predefined set of operations using \n \t\t two stacks. The operations list is defined below. This program outputs \n\t         push_swap operations that sorts the input integers.\n\n\u003e [!NOTE]  \n\u003e Because of 42 School norm requirements:\n\u003e * Each function can't have more then 25 lines of code.\n\u003e * All variables are declared and aligned at the top of each function.\n\u003e * Project should be created just with allowed functions otherwise it's cheating.\n\n## 📑 Operations List\n\nThe program is only allowed to work with two stacks: stack A and stack B. \\\nAll the numbers are initially added to stack A, and stack B is empty.\n\nThe possible operations are:\n\n| Code  | Operations                          | Action                                                 |\n|:-----:|:-----------------------------------:|:------------------------------------------------------:|\n| `sa`  | swap a                              | swaps the 2 top elements of stack a                    |\n| `sb`  | swap b                              | swaps the 2 top elements of stack b                    |\n| `ss`  | swap a + swap b                     | both `sa` and `sb`                                     |\n| `pa`  | push a                              | moves the top element of stack b at the top of stack a |\n| `pb`  | push b                              | moves the top element of stack a at the top of stack b |\n| `ra`  | rotate a                            | shifts all elements of stack a from bottom to top      |\n| `rb`  | rotate b                            | shifts all elements of stack b from bottom to top      |\n| `rr`  | rotate a + rotate b                 | both `ra` and `rb`                                     |\n| `rra` | reverse rotate a                    | shifts all elements of stack a from top to bottom      |\n| `rrb` | reverse rotate b                    | shifts all elements of stack b from top to bottom      |\n| `rrr` | reverse rotate a + reverse rotate b | both `rra` and `rrb`                                   |\n\n## 🧮 Algorithm\n\nI use `Butterfly` algorithm for sorting. Here is a short description:\n\n* First, need to generate a chunk number.\n* After I iterate through stack A look for a number, whose index is smaller than the counter (numbers count in stack B).\n* If I find that number, I do `pb` and `rb`.\n* If no, I check if the number is smaller than counter + chunk, and do only `pb`.\n* Repeat these operations until stack A becomes empty.\n* In stack B we will have numbers in order like 90-degree rotated butterfly 🦋.\n* After that, I will iterate through stack B and push the maximum index in stack A (i.e. `pa`) until stack B becomes empty.\n* After these operations, stack A becomes sorted.\n\nThe chunk number must be different depending on the numbers count. \\\nSo need to experiment with chunk number to achieve the best operations count. \\\nFor more information about the algorithm see \u003ca href=\"https://www.youtube.com/watch?v=GA9aKzl86nA\u0026ab_channel=Edu_events_mow\"\u003e\u003cb\u003ethis video\u003c/b\u003e\u003c/a\u003e. \\\nAlso, you can visualize algorithm work by this \u003ca href=\"https://push-swap-visualizer.vercel.app/\"\u003e\u003cb\u003evisualizer\u003c/b\u003e\u003c/a\u003e.\n\n## 🌟 Bonus Part\n* The Bonus exercise was to write a program called 'checker' that can read the operations from stdin and perform them on a stack of numbers.\n* Checker will display 'OK' when the given operations will sort the numbers in ascending order. Otherwise it displays 'KO'.\n* In case of an error (f.ex. operations doesn't exist) it displays 'Error'.\n\n## 👨‍💻 Usage\n### Requirements\n\nThe program is written in C language and thus needs the **gcc compiler** and some standard **C libraries** to run.\n\n### Instructions\n\n**1. Compiling the program**\n\nTo compile the program, run:\n\n```shell\n$ cd path/to/push_swap \u0026\u0026 make\n```\n\nTo compile the checker, run:\n\n```shell\n$ cd path/to/push_swap \u0026\u0026 make bonus\n```\n\n**2. How to run the program**\n\nRun the executable together with the set of numbers separated by a space:\n```shell\n./push_swap 5 7 10 4 6 8 9 2 1 3\n```\n\nTo run the checker on push_swap, use the pipe:\n```shell\nARG=\"5 7 10 4 6 8 9 2 1 3\"; ./push_swap $ARG | ./checker $ARG\n```\n\nUse `clean` to delete all object files, `fclean` to remove executable and all object files, and `re` to recompile the program:\n```shell\nmake clean / make fclean / make re\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdpetrosy%2F42-push-swap","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdpetrosy%2F42-push-swap","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdpetrosy%2F42-push-swap/lists"}