Code Monkey home page Code Monkey logo

push-swap's Introduction

push-swap

A program that attempts to find the minimum number of moves to sort a stack using a specific set of moves and one helper stack. The program outputs the shortest list of moves that it found. Includes a checker program that tests if the outputted list of instructions leads to a sorted stack.

Running push_swap

The stack can be given as separate arguments or as a string.

The first number corresponding to the number at the top of the stack.

./push_swap 5 3 1 2 4

or

./push_swap "5 3 1 2 4"

Running the checker

The checker takes the same argument(s) as push_swap, then waits for sorting instructions from the standard input.

./checker 5 3 1 2 4

Especially for larger stacks, it is easiest to run by piping the output of push_swap to the checker.

ARGS="5 3 1 2 4"; ./push_swap $(ARGS) | ./checker $(ARGS)

Allowed moves

  • pa - pushed from stack b to stack a
  • pb - pushed from stack a to stack b
  • sa - swaps the top two elements of stack a
  • sb - swaps the top two elements of stack b
  • ss - performs sa and sb simultaneously
  • ra - shifts all elements of stack a up one (first becomes last)
  • rb - shifts all elements of stack b up one (first becomes last)
  • rr - performs ra and rb simultaneously
  • rra - shifts all elements of stack a down one (last becomes first)
  • rrb - shifts all elements of stack a down one (last becomes first)
  • rrr - performs rra and rrb simultaneously

push-swap's People

Contributors

henpatsi avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.