Pebble Merchant :: Aspiration 2020 :: Question Number 7
Pebble Merchant
Problem Description
There is a pebble merchant. He sells the pebbles, that are used for shining the floor. His main duty is to take the length of the room's sides. But he sometimes mistakes doing that and the mistakes result in losses. So, he comes to you, and asks you to make a small intelligent car, which could run along the room's walls and calculate their length. The car has to come back from where it's started. This means the starting point is the same as the ending one. When the car gives the length of the room's walls, you could calculate the surface area of the floor. Knowing the surface area, you could calculate the price for covering the whole floor with pebbles.
3 kilograms of pebbles are needed for covering an area of 1 square meter .
The rate of the pebbles is $5 per kilogram.
For example
The car's measurements are illustrated, using two arrays.
Array 1 = {L, R, L, R, R, L, R, R, L, R, R, L, R, L, L, R, Z}
Where
L denotes, that the car turned Left.
R denotes, that the car turned Right.
Z denotes, that the finishing point is after the last turn.
The following picture will clear any misunderstandings (on this example Array 1 = {L,R,R,R,Z})
An element of Array 2 denotes the length (in meters), covered by the car, after taking the corresponding turn.
{3L, 4R, 2L, 3R, 2R, 4L, 5R, 4R, 2L, 3R, 2R, 1L, 2R, 2L, 2L, 1R, 2Z}
In this representation it is clearly visible that the direction from entry turning point is measured, along with the distance to the next turning point.
The last element Z in Array 1 represents that the corresponding length in the Array 2 is the final distance and the car will be at finishing point after covering this length.
Instructions to work with Open PBT Client:
- Specify the work directory path in the 'Work Directory Path' field. The path should correspond to your solution project directory.
- Download the support files by clicking the Get Dev Files.
- You will find the following three folders:
- bin
- src
- lib
- Code the solution in . java file inside the src folder
- All required files will be downloaded to your work directory. Creating additional files is strongly discouraged.
Step 1:
In your Solution File:- Implement your logic in public int[] findCost(char[] direction,int[] length) in class PebbleMerchant.
- char direction[] : Is a character array which represents turning direction of car.
- int length[] : is an integer array, which represents the length, traveled by the car, in each direction.
- You could create more methods, but do it in the same class.
Step 2:
Your solution needs to consider the following constraints.- In this problem you have to make a program for the pebble merchant.
- His main duty is to take the length of the room's sides. But he sometimes mistakes doing that and the mistakes result in losses.
- So, he comes to you and asks you to make a small intelligent car, which could run along the room's walls and calculate their length.
- The car has to come back from where it started.
- This means the starting point is the same as the ending one.
- The direction array contains only L, R and Z in UPPER CASE; otherwise return {0,0}
The Prototype of the function is
public int[ ] findCost(char[ ] direction,int[ ] length).This method takes the following arguments:
- direction is a character array, which represents the turning directions of the car.
- length is an integer array, which represents the length, traveled by the car, in each direction.
- This method returns an integer array having two elements first is the calculated area and second is the estimated cost.
The constraints are:
- The direction array contains only L, R and Z in UPPER CASE; otherwise return {0,0}
- The direction array's last element should be Z; otherwise return {0,0}
- Each element in the length array should be greater than 0; otherwise return {0,0}
Example 1
direction[] = {L,R,R,L,L,R,R,R,R,L,Z}
length[]= {2,2,1,1,1,2,5,2,2,3,1}
{18,270}
Example 2
direction[] = {L,L,R,R,L,R,R,L,R,L,R,R,L,R,L,R,R,L,Z}
length[]= {1,1,1,1,2,2,2,2,1,2,1,2,2,1,1,1,1,2,2}
{24,360}
Example 3
direction[] = {L,R,L,R,R,L,R,R,L,R,A,L,Z}
length[]= {1,2,2,2,2,2,5,2,1,2,3,2,2}
{0,0}
For Java solutions
Package Name | : | test.pebblemerchant |
File Name | : | PebbleMerchant.java |
Class Name | : | PebbleMerchant |
Function Names | : | public int[ ] findCost(char[ ] direction,int[ ] length) |
General Instructions
* | The package names, class names, method signatures are to be used as mentioned in the problem statement. Do not use your own names or change the method signatures and fields. You can add any number of additional methods. |
* | The function(s) defined above would be the only functions that would be tested. If you add a main() function for your own testing, that would not be tested. |
* | Command line options for the main() function are not supported currently. |
--
No comments:
Post a Comment