18
2
Introduction
Let's say that S1 = a...b
and S2 = ..c..
. If we place them on top of each other, we get:
a...b
..c..
We merge both strings, with the .
as the liquid character (which can overlapped). We get this:
a.c.b
If one of the string is longer than the other, we just apply the same algorithm:
a.....b
..c..
becomes:
a.c...b
and
a.....b
..c.......
becomes:
a.c...b...
If two characters collide, we just use the bottom character, e.g.
a..b
...c
becomes:
a..c
The Task
Given two non-empty strings, output the merged string. Note, you can assume that the input only contains periods and lowercase letters (or uppercase letters if that is more convenient).
Test cases
Input Output
a....b ..c... a.c..b
aaaaaa bbbbbb bbbbbb
ab.ab. b.b.b. bbbab.
a.......b c c.......b
This is code-golf, so the submission with the least amount of bytes wins!
Is input
a.....b
..c.......
possible? What's the output then? – Luis Mendo – 2016-03-04T22:22:08.780@DonMuesli That would become
a.c...b...
. – Adnan – 2016-03-04T22:22:43.500Can we output a list of characters instead of a string? – Denker – 2016-03-05T00:49:55.970
@DenkerAffe No, sorry – Adnan – 2016-03-05T00:51:59.827
Can the strings be taken in the opposite order? – Mego – 2016-03-05T04:05:34.077
Possible duplicate of Unslice a string
– timmyRS – 2016-03-05T09:46:45.830@Mego Yes, but that means that when two characters collide, the top character is used instead of the bottom. – Adnan – 2016-03-05T13:49:29.600