29
3
This was inspired by a function I recently added to my language Add++. Therefore I will submit an short answer in Add++ but I won't accept it if it wins (it wouldn't be fair)
Don't you hate it when you can multiply numbers but not strings? So you should correct that, right?
You are to write a function or full program that takes two non-empty strings as input and output their multiplied version.
How do you multiply strings? I'll tell you!
To multiply two strings, you take two strings and compare each character. The character with the highest code point is then added to the output. If they are equal, simply add the character to the output.
Strings are not guaranteed to be equal in length. If the lengths are different, the length of the final string is the length of the shortest string. The input will always be lowercase and may contain any character in the printable ASCII range (0x20 - 0x7E
), excluding uppercase letters.
You may output in any reasonable format, such as string, list etc. Be sensible, integers aren't a sensible way to output in this challenge.
With inputs of hello,
and world!
, this is how it works
hello,
world!
w > h so "w" is added ("w")
o > e so "o" is added ("wo")
r > l so "r" is added ("wor")
l = l so "l" is added ("worl")
d < o so "o" is added ("worlo")
! < , so "," is added ("worlo,")
So the final output for hello,
and world!
would be worlo,
!
More test cases
(without steps)
input1
input2 => output
programming puzzles & code golf!?
not yet graduated, needs a rehaul => prtgyetmirgduuzzlesneedsde rolful
king
object => oing
blended
bold => boln
lab0ur win.
the "super bowl" => the0usuwir.
donald j.
trumfefe! => trumlefj.
This is a code-golf so shortest code wins! Luok!
35This is the elementwise maximum of the strings, right? That doesn't seem anything like multiplying. – xnor – 2017-06-08T22:34:48.897
5Nitpick: PPCG has graduated, we just didn't get a new design yet. – Dennis – 2017-06-09T04:02:27.943
1
Possible relevant: https://codegolf.stackexchange.com/questions/74809/merging-two-strings/123187#123187
– nmjcman101 – 2017-06-09T11:40:09.810