Giter Club home page Giter Club logo

roverproblem's Introduction

Rover-Problem

Rover mars problem implemented using Java

How to run

To run this project compile every .java file in the src/ directory.

The example below shows how to do this using the command line on linux or windos PowerShell:

cd src
javac *.java

Then execute the RoverProblem file:

java RoverProblem

This will run the program in interactive mode, it will expect the inputs from the standard input from the terminal.

If you wish the program to run using inputs from a file, pass the file path and name as the first argument.

This example shows how to do this using the provided validInput.txt example file, located in the examples directory:

java RoverProblem example/validInput.txt

The input format should be the same as in the validInput.txt file:

5 5 
1 2 N 
LMLMLMLMM
3 3 E 
MMRMMRMRRM

The first indicate the plateau dimensions, then any number of rovers can be entered, one line indicating the starting position and heading, and one line indicating the sequence of instructions. The program stops reading the input and prints the output after receiving an empty line ou detecting an end of file.

There are other two example input files present in the examples folder: collision.txt which inputs a case where two rovers collide and invalidPosition.txt which inputs a case where a rover moves outside of the plateau.

Implementation details

I considered that collisions between rovers should not be allowed to happen.

I implemented this problem representing the rovers as objects with x and y coordinates, and a plateau being a list of rovers. To check for a possible collision the program goes through the list of rovers in a plateau to check for equal coordinates. This solution is more efficient memory wise than representing the entire plateau as a matrix containing all possible positions, both occupied and not. On the other hand this solution has a worse performance time than the matrix solution to check for the collisions.

roverproblem's People

Contributors

gcfernandes 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.