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 – 9 years ago@DonMuesli That would become
a.c...b...
. – Adnan – 9 years agoCan we output a list of characters instead of a string? – Denker – 9 years ago
@DenkerAffe No, sorry – Adnan – 9 years ago
Can the strings be taken in the opposite order? – Mego – 9 years ago
Possible duplicate of Unslice a string
– timmyRS – 9 years ago@Mego Yes, but that means that when two characters collide, the top character is used instead of the bottom. – Adnan – 9 years ago