Skip to content

G-Man is a video game in which G-Man has to move from one point to another on a grid (6 X 6 grid). There could be multiple paths between a source coordinate and destination coordinate and G-Man needs to reach the destination by spending least amount of power.

Notifications You must be signed in to change notification settings

AlphaCodder/power-of-gman

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

score

Geektrust Backend Challenge

Problem Statement

The problem statement can be found here Power of G-Man

Solution

The solution is a NodeJS application that takes a text file as input and prints the output to the console.

Approach

Implemented a Gman class which has the following properties and methods.

  • class Gman
    • properties

      • sourceLocation
      • targetLocation
      • totalPower
      • turns
    • methods

      • calculateMoves
      • isTurnReqInXDir
      • isTurnReqInYDir
      • calculateTurns
      • calculatePower

Core logic is implemented in calculateMoves method. This method calculates the number of moves required to reach the target location from the source location. It also calculates the number of turns required to reach the target location from the source location. It also calculates the total power required to reach the target location from the source location.

Build

NPM is the default package manager for NodeJS. NPM can install all the dependencies of a project through the package.json file. It can also update and uninstall packages. In the package.json file, each dependency can specify a range of valid versions using the semantic versioning scheme, allowing developers to auto-update their packages while at the same time avoiding unwanted breaking changes.

A sample package.json file can be downloaded from here

In your package.json file make sure you have an entry for the following:

  1. Start script which points to the execution of geektrust.js
  2. Test script to execute all the unit tests present.
"scripts": {
    "start": "node geektrust.js",
    "test": "mocha"
}

We run the following command to build you solution.

npm ci --silent

Correctness

We expect your program to take the location to the text file as parameter. Input needs to be read from a text file, and output should be printed to the console. The text file will contain only commands in the format prescribed by the respective problem.

This main file, geektrust.js should receive in the command line argument and parse the file passed in. Once the file is parsed and the application processes the commands, it should only print the output.

For e.g your geektrust.js file will look like this

const filename = process.argv[2];
// parse the file and process the command
// print the output

Execution

No build

We will execute the program using the command

node geektrust.js <absolute_path_to_input_file>

NPM

Once the npm install from the previous build process is complete, we will execute the program using the command

npm start --silent <absolute_path_to_input_file>

Unit tests

For NodeJS we support the following frameworks for unit testing

  • Mocha For both the frameworks we use Istanbul as the code coverage tool.

Execution

Mocha

After npm install Mocha based test cases are executed with the following command from the root folder

mocha test

About

G-Man is a video game in which G-Man has to move from one point to another on a grid (6 X 6 grid). There could be multiple paths between a source coordinate and destination coordinate and G-Man needs to reach the destination by spending least amount of power.

Topics

Resources

Stars

Watchers

Forks