g | x | w | all
Bytes Lang Time Link
006Japt P240613T181819ZShaggy
059Python 3.8 prerelease240613T143959ZJitse
028Perl 5 + p0231201T195956ZDom Hast
016Uiua231130T100856Zchunes
155R240612T154755Zint 21h
096Desmos231215T121013ZAiden Ch
059GNU sed E231208T133244ZPhilippo
159Python231204T083551ZGáb
099Bash231203T144905ZDavid G.
060C clang231130T162120ZAZTECCO
033Ruby231130T080416ZG B
012BQN231201T021408Zatt
097Noulith231130T215510Zbigyihsu
032J231129T234028ZJonah
133Go231130T213004Zbigyihsu
021x8664 machine code231130T211102Zm90
048JavaScript Node.js231130T003103Zl4m2
00505AB1E231130T074310ZKevin Cr
035Charcoal231130T005533ZNeil
026Retina 0.8.2231130T001751ZNeil
062JavaScript ES11231129T230457ZArnauld
026Wolfram Language Mathematica231129T231707Zatt
275Vyxal s231129T224724Zlyxal
003Jelly231129T224331ZJonathan

Japt -P, 6 bytes

ËòÀÃÕc

Try it

ËòÀÃÕc     :Implicit input of string array
Ë          :Map
 ò         :  Partition between characters
  À        :    That are not equal
   Ã       :End map
    Õ      :Transpose
     c     :Flatten
           :Implicitly join and output

Python 3.8 (pre-release), 59 bytes

f=lambda a,b:a+b and a[:a.rfind(s:=a.lstrip(a[:1]))]+f(b,s)

Try it online!

Perl 5 + -p0, 28 bytes

1 byte saved thanks to @Xcali!

s/^(.)\1*/!print$&/gem&&redo

Try it online!

Uiua, 16 bytes

/◇⊂♭⍉⬚∘⊟□[]∩⊜□∩.

Try it!

Takes lists of postive integers as input (because this saves a few bytes over strings).

enter image description here

enter image description here

enter image description here

enter image description here

enter image description here

enter image description here

R, 155 bytes

\(r,s,`!`=length,`?`=rep,`/`=\(x,n)rle(el(strsplit(x,"")))[[n]],`*`=\(x,n)c(x/n,0?max(!r/1,!s/1)-!x/1))o=Map(\(a,b,d,e)cat(a?b,d?e,sep=""),r*2,r*1,s*2,s*1)

Attempt This Online!

The solution is based on rle function ("run length encoding") which transforms a character vector into two vectors by counting and removing the repeated adjacent characters.

The smaller vectors output by rle are matched with 0's in order to have the same length as the larger ones and to avoid the recycling of the characters. Then the elements of the both character vectors are restored back to their original lengthes with the rep and output one after one in the zip-lock fashion. Note that added extra elements rep("0",0) result in character(0) which are ignored by cat.

Desmos, 96 bytes

C=sgn(L[2...]-L)^2
g(L)=∑_{n=1}^{[1...C.count]}C[n]
f(A,B)=sort(join(A,B),join(0,g(A),0,g(B)))

Ok this can probably be improved somehow but for now this is good enough.

Try It On Desmos!

Try It On Desmos! - Prettified

GNU sed -E,  63  59 bytes

The first approach did build a third string behind the two strings to be merged, but it turned out it's cheaper to invest in introducing a mark _ in the first string marking the position where to insert the chars from the second string:

s/^/_/
:1
s/_((.?)\2*)(.*,)((.?)\5*)/\1\4_\3/
/_,/!b1
s///g

The magic mainly takes place in the third line: The ERE (.?)\2* (and the same with 5) match zero or more occurences of the same character (using a backreference, which is not required for ERE by POSIX, but supported by the GNU implementation. Thus, we move those matches in front of the _.

We can't use t for looping, because an empty substitution is always possible, but that's not too expensive, because the addess pattern _, can be reused for removing.

Try it online!

Python, 160 159 bytes

from itertools import*
c,g,l=chain.from_iterable,groupby,list;f=lambda a,b:''.join(c(c(zip_longest([l(t)for r,t in g(a)],[l(t)for r,t in g(b)],fillvalue=''))))

Attempt This Online!

Edit 1: removed an extra space

Bash, 103 99 bytes

The function. Input is parameters 1 and 2. Output is variable o.

f(){
o=  
while [ "$1$2" ]
do  
c=`expr "$1" : "${1::1}*"`
o+=${1::$c}
set -- "$2" "${1:$c}"
done
}

Try it online!

Uses expr to determine the repeats of the first character, "outputs" the repeats, swaps the strings, and repeats until empty.

Due to limitations in expr, it can't handle characters [, \, or ^, or trailing single parentheses. All of these cause infinite loops, possibly with errors spewing. See the TIO for details.

I could save two characters by removing the quotes on the while statement, but this would make space not be a valid character.

C (clang), 61 60 bytes

f(a,b)char*a,*b;{*a?putchar(*a)-*++a?f(b,a):f(a,b):puts(b);}

Try it online!

Ruby, 33 bytes

f=->a,b{a[/(.)\1*/]?$&+f[b,$']:b}

Try it online!

How it works:

If the first queue is not empty, extract the first vehicle, then exchange the queues, and repeat.

If the first queue is empty, return the whole second queue.

BQN, 12 bytes

∾∾○(+`»⊸≠)⊔∾

Try it online!

Input 𝕨F𝕩. Assumes the leading character isn't a null character.

                            traffic jaaam
           ∾    join        trafficjaaam
          ⊔     group by
    +`»⊸≠        vehicle #s
 ∾○              (joined)   123445612223
                            tj raaa am ff i c
∾               join groups tjraaaamffic

Flattened group-by (∾⊔) is a little shorter than sort-by (⍋⊸⊏).

Noulith, 97 bytes

f:=\a,b->if (a.len<1)b else (c,d:=a.first,a.tail;c$if (d.len>0 and c==d.first)f(d,b)else f(b,d))

Try it online!

Explanation

f:=\a,b ->                  # recursive function
if (a.len<1) b              # return early when first input is empty
else (                      # otherwise
c,d:=a.first,a.tail;        # get first c(h)ar and the rest
c $                         # concat the first c(h)ar with
if (d.len>0 and c==d.first) # if next is a truck
f(d,b)                      # the rest of the truck
else f(b,d))                # otherwise the next lane

J, 32 bytes

[:;(,/:,&(#\))&(<;.1~2~:/\'_'&,)

Attempt This Online!

The 2nd part of this is the only interesting insight:

Go, 133 bytes

func f(a,b string)string{if len(a)<1{return b}
c,a:=a[0],a[1:]
if len(a)>0&&c==a[0]{return string(c)+f(a,b)}
return string(c)+f(b,a)}

Attempt This Online!

Recursive function.

Explanation

func f(a,b string)string{
if len(a)<1{return b}    // return early when first input is empty
c,a:=a[0],a[1:]          // get the current c(h)ar
if len(a)>0&&c==a[0]{    // if the next c(h)ar is the same...
return string(c)+f(a,b)} // recurse to get the truck
return string(c)+f(b,a)} // otherwise move on to the next lane

x86-64 machine code, 21 bytes

AA 3A 06 74 03 48 87 D6 AC 84 C0 75 F3 52 5E 3A 06 A4 75 FB C3

Try it online!

Following the standard calling convention for Unix-like systems (from the System V AMD64 ABI), this takes in RDI an address at which to place the result, as a null-terminated byte string, and in RSI and RDX, addresses of the inputs, as null-terminated byte strings. The starting point is after the first 8 bytes.

In assembly, rearranged for easier reading:

f:  lodsb           # Load a byte from address RSI into AL, advancing the pointer.
    test al, al     # Check the value of that byte.
    jnz r           # Jump if it's nonzero.
(This section actually comes first.)
r:  stosb           # Write that byte to the output string, advancing the pointer.
    cmp al, [rsi]   # Compare that byte to the next byte in the string.
    je f            # Jump if they are equal.
    xchg rsi, rdx   # (Otherwise) Swap the pointers (in RSI and RDX).
(From here, continue at the beginning.)
(When the byte is zero, continue to here.)
    push rdx; pop rsi   # Transfer the other pointer from RDX to RSI.
r1: cmp al, [rsi]       # Compare the value at that address to AL, which is 0.
    movsb               # Write the byte from address RSI to the output string,
                        #  advancing both pointers.
    jne r1              # Jump back if the byte was not equal to 0.
    ret                 # Return.

JavaScript (Node.js), 52 48 bytes

f=([c,...a],b)=>c?[c,...c==a[0]?f(a,b):f(b,a)]:b

Attempt This Online!

Array IO, though inputting string usually work

05AB1E, 5 bytes

€γõζS

Input as a pair of strings; output as a list of characters.

Try it online or verify all test cases.

Explanation:

€      # Map over both strings in the (implicit) input-pair:
 γ     #  Split them into equal adjacent groups of substrings
   ζ   # Zip/transpose this list of lists,
  õ    # using an empty string ("") as filler for unequal length lists
    S  # Convert this list of pairs of strings to a flattened list of characters
       # (which is output implicitly as result)

Charcoal, 35 bytes

F²⊞υ⪪⮌S¹W∧⌊υ⊟§υ⁰«ι¿⌕⮌§υ⁰ι≔⮌υυ»W⌈υ⊟ι

Try it online! Link is to verbose version of code. Explanation: Seems to be a similar idea to @l4m2's answer, but it just took me that long to think of it after writing my Retina answer that he got there first.

F²⊞υ⪪⮌S¹

Input the two strings, reversing them and splitting them into characters so that they can be processed more easily.

W∧⌊υ⊟§υ⁰«

Until one queue is empty, remove the next character from the first queue, ...

ι

... print it, and...

¿⌕⮌§υ⁰ι

... if the next character in this queue is from a different vehicle, then...

≔⮌υυ

... switch the queues.

»W⌈υ⊟ι

Output the remaining vehicles from the other queue.

Retina 0.8.2, 26 bytes

O$#`.(?<=(\2*(.))+)
$#1
¶

Try it online! Takes input on separate lines but link is to test suite that splits on commas for convenience. Explanation:

O$#`.(?<=(\2*(.))+)
$#1

Sort each character by its vehicle index in its queue. This is a stable sort so that the first vehicle of the first queue sorts first followed by the first vehicle of the second queue etc. The newline is not considered for the sort but it's used by the lookbehind to find the front of the second queue.

The vehicles were sorted without regard for the placement of the newline which is just unnecessary at this point.

JavaScript (ES11), 62 bytes

Expects ([str1, str2]).

a=>[...a+a].map((_,i)=>a[i&1].match(/(.)\1*/g)?.[i>>1]).join``

Attempt This Online!

Wolfram Language (Mathematica), 26 bytes

Flatten[Split/@#,{2,1,3}]&

Try it online!

Input and output lists of characters.

Vyxal s, 22 bitsv2, 2.75 bytes

vĠ∩

Try it Online!

Bitstring:

1000110100011111100101

The footer inserts a newline for test case purposes. Port of the jelly answer.

Explained

vĠ∩­⁡​‎‎⁡⁠⁡‏⁠‎⁡⁠⁢‏‏​⁡⁠⁡‌⁢​‎‎⁡⁠⁣‏‏​⁡⁠⁡‌­
vĠ   # ‎⁡Vectorise group-by
  ∩  # ‎⁢Transpose
💎

Created with the help of Luminespire.

Jelly, 3 bytes

ŒgZ

A full program that accepts a pair of the two strings as the first argument and prints the resulting single lane.

Try it online!

How?

ŒgZ - Main Link: pair of lists of characters
Œg  - group runs of equal elements of each
  Z - transpose
    - implicit, smashing print