Coder Social home page Coder Social logo

cta-ride-fare-utility's Introduction

CTA Ride Fare Utility


Run npm install if you want to use integrated tests (Jest).

Run The App


To run the application, you can use the following command: node index.js This will start the application and display the prompt for entering the fare amount and Gaavo pieces. The user can enter the Gaavo pieces in the following format: 7 1 4 6. The output of the application will either be the combination of Gaavo pieces that add up to the fare or "You cannot make the fare" if no combination of pieces adds up to the fare.

To run Test

npm install to install dev dependencies - Jest npm jest

Solution


The problem can be solved using dynamic programming. The algorithm is based on finding all the possible combinations of pieces which add up to the fare. To make this process more efficient, we can use memoization, which is caching the results of expensive function calls and returning the cached result when the same inputs occur again. This approach can be implemented using the concept of recursion.

I wrote a function findGaavoCoinsRec that takes two parameters, the fare amount and an array of pieces. In the function, we will loop through all the pieces and check if the current piece is equal to the fare, if yes we return an array containing only that piece. If the current piece is less than the fare, we subtract the current piece from the fare and recursively call the function with the remaining fare and the remaining pieces, excluding the current piece. We store the result of each call in a cache so that we don't recalculate the result for the same input. If no combination of pieces adds up to the fare, we return a message "You cannot make the fare".

This utility application has been developed using Node.js, which will allow the user to enter the fare and the pieces they have, and it will output the combination of pieces that add up to the fare or a message "You cannot make the fare".

cta-ride-fare-utility's People

Contributors

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