Giter Site home page Giter Site logo

raghuboosetty / airbus_seating_algorithm Goto Github PK

View Code? Open in Web Editor NEW
1.0 1.0 1.0 175 KB

Program that helps seat audiences in a flight based on the following input and rules

License: MIT License

Ruby 100.00%
algorithm-challenges airplane seating ruby-application cli automated-testing

airbus_seating_algorithm's Introduction

Setup

First, install Ruby.

Then run the following commands under the airplane-seating-algorithm dir.

$ ruby -v # confirm ruby version | ruby 2.5.1
$ gem install bundler # install bundler to manage dependencies
$ bin/setup

Usage

You can run the program from airplane-seating-algorithem by giving 2 types of input:

  1. File as input
  2. Command line input

The format of it should be:
A 2D Array of seat layout in cols and row, followed by a space and total number of passengers
e.g: [[3,2], [3,4], [2,3]] 21

File as input

# please add inputs with a new line seperator to the file_input.txt in root directory or pass any other file having input in similar format

$ bin/run_seating_airplane file_input.txt

Command line input

# run the same command without file params will wait for command line input.
# please add inputs with a new line seperator in the format of example shown below
# hit 'q' to exit the program

$ bin/run_seating_airplane
$ [[3,2], [3,4], [2,3]] 21
$ q

Functional Test

A fully functional test suite has beed added under airplane-seating-algorithm/functional_spec dir. You can run the full test suite from airplane-seating-algorithm dir by running

$ bin/run_functional_specs

Algorithm Logic

  1. Create empty seating layout in 3D array based on given 2D array. The 3rd dimension points to the number of the block. The 3D array has a structure like: [block_number, row_number, column_number]
  2. Group Asile, Window and Center seats under each block based on given 2D array. The grouped seats are in 3D array format that holds the exact index of the seat in the structure mentioned in point 1.
  3. Sort each of Asile, Window and Center seats from left to right and top to bottom
  4. Combine all seats to form a ordered 3D array having the indexes of seating position
  5. Allot the seats created in step 1 to passengers based on 3D positions created in step 4
  6. Print the layout in the given format

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.