JS coding challenge: crossing tramways
3 trams are moving on different railways from one station to another, with the same speed. They need to circulate from end to end on their own railway.
Every tram has assigned different number of people. In case 2 trams or more arrive to a cross at the same time, the one with the higher number of persons should pass first. We need to make the trams circulate on their railways avoiding collisions and following the priority rules.
A graphical solution for the problem is required.
Notes:
- The space between stations are the same.
- A tram avoids a collision stopping in the previous station and letting the tram with higher priority to get the next station.