For two trains A and B to pass one another they each have to travel their combined lengths to pass clear. When they are travelling in opposite directions, the time to cover this distance is given by:
1to=(LA+LB)/(vA+vB)=10 secs, where L represent length and speed of the trains (subscript identifies which train). Speed is measured in metres/second.
When travelling in the same direction time to pass is given by:
1ts=(LA+LB)/(vA-vB)=30 secs.
If LA>LB then the changed length of LA becomes LA/2. It takes 30-8=22 seconds:
2ts=(LA/2+LB)/(vA-vB)=22 secs.
LA-LB=25m.
The length of the tunnel is 2LA and to pass completely through the tunnel train A has to travel 2LA+LA=3LA metres. Therefore, train takes 3LA/vA seconds to completely pass through the tunnel.
We have to assume that the speed of each train is constant for the whole exercise.
All distances and lengths can be written in terms of LA, so LB=LA-25 metres. So we can rewrite the equations:
1to=(2LA-25)/(vA+vB)=10 secs, 1ts=(2LA-25)/(vA-vB)=30 secs, 2ts=(3LA/2-25)/(vA-vB)=22 secs.
We need t=3LA/vA, the time it takes for train A to pass through the tunnel.
(2LA-25)/(vA+vB)=10, so 2LA-25=10vA+10vB; 2LA/vA-25/vA=10+10vB/vA; ⅔t-25/vA=10+10vB/vA;
(2LA-25)/(vA-vB)=30, so 2LA-25=30vA-30vB; ⅔t-25/vA=30-30vB/vA;
(3LA/2-25)/(vA-vB)=22, so 3LA-50=44vA-44vB; t-50/vA=44-44vB/vA.
10+10vB/vA=30-30vB/vA; 40vB/vA=20, vB/vA=½, so we know vB in terms of vA. So we can substitute for vB/vA.
⅔t-25/vA=10+5=15 (also ⅔t-25/vA=30-15=15); t-50/vA=44-22=22. We now have two equations and two unknowns:
⅔t-25/vA=15; t-50/vA=22.
4t/3-50/vA=30; 50/vA=4t/3-30=t-22, ⅓t=8, t=24 seconds is the time for train A to completely pass through the tunnel.