In this challenge you will take two lists as input and you will zip them. The zip can be defined with this recursive expression:
\$ \mathrm{zip}(a,b) = \begin{cases} \left[\,\,\right] & a = \left[\,\,\right] \\ [a_0]\mid\mid\mathrm{zip}(b, t) & a = [a_0] \mid\mid t \end{cases} \$
or this Haskell program if you would like:
zip [] _ = []
zip (x:xs) ys = x : zip ys xs
In simple terms you create a list which alternates between elements of the two input lists, starting with the first element of the first list, then the first element of the second list and so on, until one of the lists doesn't have the next element, then you stop.
For example if we zip [1,2,3,4,5]
and [11,12,13]
we get [1,11,2,12,3,13,4]
. Every element appears in the output except 5
, which is missing because the second list ran out before we reached it.
Task
As input you will take two lists of positive integers and output the result of zipping them as described above. I use the term "first" and "second" when referring to the inputs, but you may take the two lists in the opposite order (although this choice must be consistent, you cannot e.g. swap the order of the inputs depending on what they are).
This is code-golf so the goal is to minimize your source code as scored in bytes.
Test cases
[] [] -> []
[] [1,2,3] -> []
[1,2,3] [] -> [1]
[1,2] [3] -> [1,3,2]
[1,2,3,4,5] [11, 12, 13] -> [1,11,2,12,3,13,4]
[9,9,9] [8,8,8] -> [9,8,9,8,9,8]
[1,2,3] [4,5,6,7] -> [1,4,2,5,3,6]
As a word of advice if your language has a built-in which solves the task try and solve the task without the builtin and post both solutions as a single answer. It's more interesting to read solutions like that and it will almost certainly be more fun for you to golf.