Skip to content

Latest commit

Β 

History

3 Commits

Folders and files

NameName
Last commit message
Last commit date
Β 
Β 
Β 
Β 

Repository files navigation

Move Optimizer Project 🐾

A simple function that calculates the resultant movement based on given cardinal directions (NORTH, SOUTH EAST, WEST) and returns the simplified path.

Original problem

Direction Catastrophe

A very simple problem with many different solutions, but the main aim is to solve it in the most efficient way. A man was given directions to go from point A to point B. The directions were: "**SOUTH*", "*NORTH", "WEST", "EAST". Clearly "NORTH" and "SOUTH" are opposite, "WEST" and "*EAST*" too. Going to one direction and coming back in the opposite direction is a waste of time and energy. So, we need to help the man by writing a program that will eliminate the useless steps and will contain only the necessary directions.

For example: The directions ["NORTH", "SOUTH", "SOUTH", "EAST", "WEST", "NORTH", "WEST"] should be reduced to ["WEST"]. This is because going "NORTH" and then immediately "SOUTH" means coming back to the same place. So we cancel them and we have ["SOUTH", "EAST", "WEST", "NORTH", "WEST"]. Next, we go "SOUTH", take "EAST" and then immediately take "WEST", which again means coming back to the same point. Hence we cancel "EAST" and "WEST" to giving us ["SOUTH", "NORTH", "WEST"]. It’s clear that "SOUTH" and "NORTH" are opposites hence canceled and finally we are left with ["WEST"].

Features ✨

  • βœ… Reduces redundant movements by implementing simple vector maths

Installation & Usage πŸ› οΈ

  1. Clone the repository using:

    git clone https://github.com/BeanyTheCoder/move_optimizer
  2. Navigate to the project directory using:

    cd move_optimizer
  3. Run the script:

    python main.py

Example Usage

print(move("NORTH", "SOUTH", "EAST", "WEST", "NORTH", "WEST", "EAST"))
# Output: ['NORTH']

Technologies Used πŸ› οΈ

  • Python

License πŸ“

This project is licensed under the MIT License.

Author πŸ‘€

My name is Alexander Afoko Jnr, a passionate 15-year-old programmer from Ghana.

I'm focused on expanding my portfolio and improving my skills as a programmer.

Contact πŸ“§

About

No description, website, or topics provided.

Resources

Stars

1 star

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages