In traffic engineering, the late merge or zipper method is a convention for merging traffic into a reduced number of lanes. Drivers in merging lanes are expected to use both lanes to advance to the lane reduction point and merge at that location, alternating turns. The late merge method has not been found to increase throughput (the number of vehicles that pass through a point in a given period of time). However, it considerably reduces queue length because drivers use the ending lane until its end and reduces speed differences between the two lanes, increasing safety.

ritsen
Ritsen waar twee rijstroken samenkomen tot één enkele rijstrook.

Governments hold campaigns to promote the late merge method because irritation, aggression and feelings of insecurity easily occur while zipping. Often drivers who change lanes too early do not like to see other drivers continue until the end of the drop-away lane, even though this late merging is encouraged by the authorities. In Belgium and Germany, a driver can be penalized for not using the late merge method. In Austria only where a traffic sign so indicates.

Most states in the United States require merging traffic to yield to through traffic which already exists in the lane they wish to enter. This further complicates the common understanding of proper merging protocol, as even though zipper merging is widely encouraged, those doing so are still legally required to yield, and those who choose not to let them merge are not technically doing anything wrong legally.

Assignment

We'll implement three different ways to merge the elements of two given sequences (list or tuple) into a new list (list).

In all three cases, merging happens alternately: we first append the first element of the first sequence to the new list, then the first element of the second sequence, the second element of the first sequence, the second element of the second sequence, and so on.

In all three cases, merging also happens pairwise: if the $$i$$-th element of the first sequence is appended, the $$i$$-th element of the second sequence must be appended as well. The three implementations behave exactly the same if the two given sequences have the same length. But they differ in handling sequences of different lengths.

Your task:

Example

>>> merge(('A', 'B', 'C'),  [1, 2, 3])
['A', 1, 'B', 2, 'C', 3]
>>> merge(['A'], [1, 2, 3, 4])
['A', 1]
>>> merge(('A', 'B'),  (1, 2, 3, 4))
['A', 1, 'B', 2]
>>> merge(('A', 'B', 'C'),  [1, 2])
['A', 1, 'B', 2]

>>> weave(('A', 'B', 'C'),  [1, 2, 3])
['A', 1, 'B', 2, 'C', 3]
>>> weave(['A'], [1, 2, 3, 4])
['A', 1, 'A', 2, 'A', 3, 'A', 4]
>>> weave(('A', 'B'),  (1, 2, 3, 4))
['A', 1, 'B', 2, 'A', 3, 'B', 4]
>>> weave(('A', 'B', 'C'),  [1, 2])
['A', 1, 'B', 2, 'C', 1]

>>> zipper(('A', 'B', 'C'),  [1, 2, 3])
['A', 1, 'B', 2, 'C', 3]
>>> zipper(['A'], [1, 2, 3, 4])
['A', 1, 2, 3, 4]
>>> zipper(('A', 'B'),  (1, 2, 3, 4))
['A', 1, 'B', 2, 3, 4]
>>> zipper(('A', 'B', 'C'),  [1, 2])
['A', 1, 'B', 2, 'C']

Epilogue

In 2008, physicist Yuki Sugiyama1 of the University of Nagoya demonstrated why traffic jams sometimes form in the absence of a bottleneck. He spaced 22 drivers around a 230-meter track and asked them to proceed as steadily as possible at 30 km/h, each maintaining a safe distance from the car ahead of it.

Because the cars were packed quite densely, irregularities began to appear within a couple of laps. When drivers were forced to brake, they would sometimes overcompensate slightly, forcing the drivers behind them to overcompensate as well. A stop-and-go wave developed: cars arriving at the back of the jam were forced to slow down, and cars reaching the front could accelerate again to normal speed, producing a living wave that crept backward around the track.

Interestingly, Sugiyama found that this phenomenon arises predictably in the real world. Measurements on various motorways in Germany and Japan have shown that free-flowing traffic becomes congested when the density of cars reaches 40 vehicles per mile. Beyond that point, the flow becomes unstable and stop-and-go waves appear. Because it's founded in human reaction times, this happens regardless of the country or the speed limit. And as long as the total number of cars on the motorway doesn't change, the wave rolls backward at a predictable 12 km/h.

Sugiyama told the following to Gavin Pretor-Pinney for his book The wavewatcher's Companion2:

Understanding things like traffic jams from a physical point of view is a totally new, emerging field of physics. While the phenomenon of a jam is so familiar to us, it is still too difficult to truly understand why it happens.

Resources