Complex Coding Round
Complex Coding Round
If the vehicle passes 3 toll gates, it has to pay in all the 3 toll
Implementation
In our program the moves taken by the computer and the human are
chosen randomly. We use rand() function for this.
What more can be done in the program?
The program is in not played optimally by both sides because the
moves are chosen randomly. The program can be easily modified so
that both players play optimally (which will fall under the category
of Artificial Intelligence). Also the program can be modified such
that the user himself gives the input (using scanf() or cin).
The above changes are left as an exercise to the readers.
Winning Strategy – An Interesting Fact
If both the players play optimally then it is destined that you will
never lose (“although the match can still be drawn”). It doesn‟t
matter whether you play first or second.In another ways – “ Two
expert players will always draw ”.
Isn‟t this interesting ?
3) Advanced programming.
You are given coordinates as input
(0 0 ) (0 1 ) ( 0 2) (0 3) (1 5) (1 4 ) (3 5 )
1. Check if the given points lie in the same line
2. GIven a point find the points on the largest line [in terms of the points
it contain ] passing through that point
Input : 0 1
Output : (0 0 ) (0 1) (0 2 ) (0 3 )
3. Given 2 points find the points in between them.
Input (0 0) (0 3 )
Output : (0 1) (0 2 )
4. Find the number of points in the line with the largest number of points
in it.
5. Given a point print all the lines passing through it [ie for each line
print the points in it ]
4) We were asked to develop a mini-project „Invoice Management‟ with
the following modules :
1. Add a customer
2. Add an invoice
3. Add items to an invoice
4. List all customers
5. List all invoices
6. List all invoices of a customer
7. Display the full details of an invoice
5) Those who have solved 4 or above problems has shortlisted for 3rd
round.It was a gaming round.
Size of the array is given were w is wall, g ground, o ball, numbers are
bricks.
I/p size 7
Number of bricks 6
Position (2, 2)(2, 3)(2, 4)(3, 2)(3, 3)(3, 4)
Ball:5(life)
wwwwwww
w w
w 1 1 1 w
w 1 1 1 w
w w
w w
w g g o g g w
There are three commands St, lt, rt straight, left, right respectively.
If it is st the ball moves straight .if there any brick(1) along the way it hit
it .then brick disappear.ball back to original position.if there is no brick
.it come to initial position.
I/p st
O/p
wwwwwww
w w
w 1 1 1 w
w 1 1 w
w w
w w
w g g o g g w
Ball count:5
I/p lt
O/p
wwwwwww
w w
w 1 1 1 w
w 1 w
w w
w w
w g o g g g w
Ball count:4
(Lt : ball moves diagonally left there is no bricK on the way so it hit the
wall reflect back horizontally there is a brick(3, 2) after hitting it it
moves downwards ball position changed.hence ball count get reduced.
On moving downwards is there any brick that also disappear.)
Same for rt but moves diagonally right.
This is first module.In second module each brick has value for each hit
value get reduced.it disappear only when it become zero.
7)
Lift system
There were 8 modules
1. Display the position of Lift
Lift : L1 L2 L3 L4 L5
Floor: 0 0 0 0 0
Input : 2 5
Output : L1 is assigned
Lift : L1 L2 L3 L4 L5
Floor: 5 0 0 0 0
Lift : L1 L2 L3 L4 L5
Floor: 5 2 7 9 0
Input : 4 10
Output :
L1 is assigned
Lift : L1 L2 L3 L4 L5
Floor: 10 2 7 9 0
R3 | - - - |
R2 | - - - |
R1 | - - - |
C1 C2 C3
Each of the 9 cells can either be empty or filled with an atom. R3, R2, R1 are the
rays that originate from the left. C1, C2, C3 are the rays that originate from the
bottom of the box.
Input : Position of the atoms and the rays that gets originated from the outside of
the box.
Eg.) 3
31
22
13
3
R3 C1 C3
Rule1:
A ray that has an atom in its path should print „H‟ (Hit) If it does not have any
atoms in its path, the ray should pass to the other side.
C1 C3
R3 | - - - | R3
H |- X -|
R1 | - - - | R1
C1 H C3
Rule2&3:
A ray that has an atom in its diagonal adjacent position should refract.
H |- - -|
H |X - -|
R |- X -|
R H R
H |- X -|
R2 | - - - | C3
|- - -|
R2 C3
Rule4:
A ray that has atoms in both of the diagonal adjacent positions should reflect back.
Input ray: C2
|- - -|
|X - X|
|- - -|
R
Input ray: R2
|- X -|
R |- - -|
|- X -|
Rule5:
The deflection of rays should happen in the order of the input rays.
The final task was to implement these rules for dynamic matrix size.
H |- - - X|
|- - - -|
|- X - -|
|- - - -|
H
The final task was very confusing and it had to handle all the cases. There are
chances for a ray to end at the starting position if the number of rows and columns
are more than 5.
Output 1:
Taxi can be allotted.
Taxi-1 is allotted
Input 2:
Customer ID: 2
Pickup Point: B
Drop Point: D
Pickup Time: 9
Output 1:
Taxi can be allotted.
Taxi-2 is allotted
(Note: Since Taxi-1 would have completed its journey when second
booking is done, so Taxi-2 from nearest point A which is free is
allocated)
Input 3:
Customer ID: 3
Pickup Point: B
Drop Point: C
Pickup Time: 12
Output 1:
Taxi can be allotted.
Taxi-1 is allotted
Output:
Taxi-1 Total Earnings: Rs. 400
1 1 A B 9 10 200
3 3 B C 12 13 200
Taxi-2 Total Earnings: Rs. 350
2 2 B D 9 11 350