Giter VIP home page Giter VIP logo

valet-parking's Introduction

Valet Parking

Go

Running the program on a bare Ubuntu 16.04 VM

  1. Install Go
sudo apt-get update
sudo apt-get -y upgrade
wget https://dl.google.com/go/go1.16.4.linux-amd64.tar.gz
sudo tar -xvf go1.16.4.linux-amd64.tar.gz
sudo mv go /usr/local
  1. Setup Go Env
export GOROOT=/usr/local/go
export PATH=$GOROOT/bin:$PATH
  1. Clone Project
git clone https://github.com/sudaraka94/valet-parking.git
cd valet-parking
  1. Run Tests
go test ./...
  1. Run the program
go build -o .
./main
  1. Run the program with a custom data file
./main -data=<path to datafile>

Running with docker

  1. Clone the repository
git clone https://github.com/sudaraka94/valet-parking.git
cd valet-parking
  1. OPTIONAL : Replace the datafile inside project directory with the desired datafile
  2. Build docker image
docker build --tag valet-parking .
  1. Run on docker
docker run -it valet-parking

Design Decisions

  • You can find all the utility methods inside util.go file
  • I tried to minimize the usage of third party libraries and do most of the implementations myself

Algorithm

Here is the basic algorithm used in this program. We can separate out the algorithm into four sections,

1. Adding a new vehicle to the park - Overall time complexity : O(n)

  • Look for an available slot with the least slot number - Time Complexity: O(n)
  • Mark the slot as occupied - Time Complexity: O(1)
  • Keep reference of the slot in a hashmap with the vehicle registration number - Time Complexity: O(1)

2. Removing a vehicle from the park - Overall time complexity : O(1)

  • Lookup the vehicle in the hashmap using the vehicle registration number - Time Complexity: O(1)
  • Remove the vehicle from the hashmap and mark the slot available - Time Complexity: O(1)
  • Calculate the fare - Time Complexity: O(1)

Logger implementation

Throughout the whole project, Logger is exposed through an interface. Currently logger interface is implemented by cliLogger, which directly writes to the std out. But in case we need to writeout the results to a file, we can easily do so by introducing a Logger implementation which writes to a file. Logger type can be made configurable via config.yml

logger_config:
  logger_type: "cli" #allowed logger types: cli

Configurability

In this application, supported types of vehicles are configurable. On the application start, it fetches configurations from confi.yml and adjusts accordingly. For an example, if we need to add a third vehicle type we just have to define the vehicle type in the config.yml.

eg:

vehicle_types:
  - name: car
    price_per_hour: 2 #pricePerHour in USD
  - name: motorcycle
    price_per_hour: 1 #pricePerHour in USD
  - name: van
    price_per_hour: 3 #pricePerHour in USD

valet-parking's People

Contributors

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