Giter Site home page Giter Site logo

php-interview's Introduction

A courier on a motorcycle is delivering packages. There are several delivery orders: A, B, C, etc. Each order consists of two points (addresses). For each order, the courier should pick up the parcel at the first address (B1) and deliver it to the second address (B2).

The route time in minutes between all points and the courier is specified in the file. For example, for data2.txt file, the travel time from the courier (CR) to point B1 is 14 minutes, and from point B2 to the courier (CR) is 53 minutes.

   CR A1 A2 B1 B2 C1 C2
CR  0 97 36 14 52 59 89
A1 94  0 68 14 63 25 30
A2 38 65  0 20 20 56 82
B1 13 14 20  0 56  4 99
B2 53 58 21 58  0 17 85
C1 61 27 57  4 16  0 84
C2 89 31 79 99 90 78  0

Solve the problems below. Feel free to use Google, StackOverflow, and PHP documentation if needed.
You you don't have to write your own file parser, there's already a FilePaster class in the code.
You can modify the code if needed.

Problem 1

Find the nearest order to the courier. Modify the script problem1.php so that it returns
the name of the point (for example, B1) to which the courier should go to get his first parcel as soon as possible.

php problem1.php data1.txt
Check your solution.
Data file Command Expected result
data1.txt php problem1.php data1.txt A1
data2.txt php problem1.php data2.txt B1
data3.txt php problem1.php data3.txt C1

Problem 2

Find the most optimal route to deliver all orders in minimum time.
The courier can carry maximum 2 parcels at the same time.

php problem2.php data1.txt

Modify the problem2.php script so that it returns the route points on the first line
and the total route time on the second line. For example:

A1 B1 B2 A2
175
Check your solution.
Data file Command Expected result
data1.txt php problem2.php data1.txt Route: A1 B1 B2 A2
Time: 175
data2.txt php problem2.php data2.txt Route: B1 C1 B2 A1 C2 A2
Time: 201
data3.txt php problem2.php data3.txt Route: C1 C2 A1 A2 B1 B2
Time: 95

If you wish, optimize the code and test your solution on files with large number of orders:

Data file Command Expected result
huge1.txt php problem2.php huge1.txt Route: F1 F2 D1 E1 E2 D2 C1 B1 C2 A1 B2 A2
Time: 314
huge2.txt php problem2.php huge2.txt Route: C1 B1 C2 G1 B2 E1 G2 F1 E2 F2 D1 H1 H2 A1 A2 D2
Time: 340

php-interview's People

Stargazers

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