| Bytes | Lang | Time | Link |
|---|---|---|---|
| 028 | tinylisp 2 | 230927T184136Z | DLosc |
| 095 | AWK | 250826T121100Z | xrs |
| 034 | Rust | 230427T152314Z | JSorngar |
| 121 | Go | 230107T172939Z | bigyihsu |
| 003 | Thunno 2 | 230425T182922Z | The Thon |
| 022 | Arturo | 230425T164622Z | chunes |
| 051 | C gcc | 230108T105538Z | l4m2 |
| 026 | Python 3 | 230107T152138Z | Joao-3 |
| nan | 230107T145941Z | The Thon | |
| 005 | Pyth | 221027T054819Z | hakr14 |
| 004 | Factor | 210326T083456Z | chunes |
| 048 | Knight | 220803T213811Z | naffetS |
| 003 | Vyxal | 210302T020447Z | lyxal |
| 029 | Python 3 | 170609T213840Z | ovs |
| 086 | Excel | 210309T185946Z | Axuary |
| 003 | 05AB1E | 210309T171432Z | Makonede |
| 067 | Perl 5 lF | 171109T060653Z | Xcali |
| 002 | Husk | 201104T155956Z | Razetime |
| 009 | Japt | 201104T154359Z | Shaggy |
| 046 | Erlang escript | 200314T072929Z | user9206 |
| 017 | Kotlin | 200314T074408Z | snail_ |
| 009 | Burlesque | 200314T155237Z | DeathInc |
| nan | Java 8 | 170609T073547Z | Kevin Cr |
| 096 | R | 180608T131313Z | JayCe |
| 023 | GolfScript | 180601T094242Z | wastl |
| 055 | Prolog SWI | 180530T040058Z | ASCII-on |
| 003 | Cjam | 180530T063517Z | Chromium |
| 013 | Japt v2.0a0 | 180525T013534Z | Bubbler |
| 008 | Add++ | 170609T062539Z | caird co |
| 066 | Swift | 171208T222109Z | Endenite |
| nan | Java | 171208T013512Z | Kitten |
| 049 | Whispers | 171207T182038Z | caird co |
| 020 | Axiom | 171109T071323Z | user5898 |
| 059 | Common Lisp | 171109T074019Z | Renzo |
| 186 | Acc!! | 171108T214402Z | DLosc |
| 009 | Pip | 171108T205052Z | DLosc |
| 045 | JavaScript ES6 | 170609T075517Z | Neil |
| 064 | Java 8 + Eclipse Collections | 170609T134435Z | Nathan M |
| 037 | Kotlin | 170612T015125Z | Redrield |
| 025 | J | 170811T085242Z | Jonah |
| 002 | Husk | 170811T151027Z | ბიმო |
| 022 | J | 170811T144738Z | miles |
| 017 | Charcoal | 170609T194844Z | Neil |
| 036 | Retina | 170609T084047Z | Neil |
| 014 | k | 170714T193303Z | skeevey |
| nan | 170612T133743Z | Ozz Nixo | |
| 049 | Javascript ES2015 | 170609T150023Z | thaliaar |
| 033 | Julia 0.5 | 170611T170909Z | pasbi |
| 021 | V | 170608T232304Z | DJMcMayh |
| 034 | Python 2 | 170608T230322Z | totallyh |
| 043 | Aceto | 170609T153247Z | L3viatha |
| 047 | JavaScript ES6 | 170609T150801Z | Rick Hit |
| 058 | C | 170609T124903Z | Khaled.K |
| 028 | Retina | 170609T131827Z | Martin E |
| 067 | C# | 170609T132727Z | grabthef |
| 008 | Alice | 170609T130749Z | Martin E |
| 119 | Micro | 170609T130703Z | raddish0 |
| 103 | R | 170609T123056Z | djhurio |
| 022 | APL Dyalog | 170609T120311Z | Adá |
| 008 | MATL | 170608T223800Z | Luis Men |
| 078 | C# | 170609T073031Z | LiefdeWe |
| 052 | PHP>=7.1 | 170608T233435Z | Jör |
| 031 | Clojure | 170609T073822Z | NikoNyrh |
| 075 | PowerShell | 170609T071319Z | Tessella |
| 012 | CJam | 170608T230142Z | Luis Men |
| 005 | Jelly | 170609T040530Z | Dennis |
| 004 | 05AB1E | 170609T063857Z | Adnan |
| 078 | Mathematica | 170609T030728Z | user2027 |
| 006 | Jelly | 170609T023113Z | Leaky Nu |
| 016 | Japt | 170608T233348Z | ETHprodu |
| 102 | Mathematica | 170608T224828Z | ZaMoC |
| 022 | Perl 6 | 170608T231403Z | Sean |
| 011 | Haskell | 170608T224524Z | nimi |
tinylisp 2, 28 bytes
(\(S T)(,(zip-with max S T)"
Explanation
The library functions zip-with and max do almost the entire task.* The only catch is that zip-with returns a list of codepoints, and we want a string. The easiest way to convert is to concatenate an empty string using , (short for concat).
* When I first answered this challenge, I had not yet implemented zip-with and max in the standard library. Here's my original 46-byte solution without those functions:
(\(S T)(,(m(p a(\(C D)(?(< C D)D C)))(z S T))"
Explanation:
(\(S T)(,(m(p a(\(C D)(?(< C D)D C)))(z S T))""))
(\ ) ; Lambda function
(S T) ; taking two strings S and T:
(z S T) ; Zip (-> list of pairs of codepoints)
(m ) ; Map to each pair:
(p a ) ; Apply to its two items:
(\ ) ; Lambda function
(C D) ; taking two integers C and D:
(?(< C D)D C) ; If C < D, then D, else C (i.e. max)
; Now we have a list of codepoints...
(, "") ; Concat "", converting to string
AWK, 95 bytes
@load"ordchr"
1~NR{l=split($0,a,X)}2~NR{for(;i++<(l<NF?l:NF);)printf(ord($i)>ord(d=a[i])?$i:d)}
Rust, 34 bytes
|a,b|a.zip(b).map(|(i,j)|i.max(j))
which takes in two iterators over chars and returns another. This only works by shunting the following obscene type into the header code:
for<'a> fn(std::str::Chars<'a>, std::str::Chars<'a>) -> std::iter::Map<std::iter::Zip<std::str::Chars<'a>, std::str::Chars<'a>>, fn((char, char))->char>
If iterators over chars do not count as reasonable input/output I can instead manage
60 bytes
|a,b|a.chars().zip(b.chars()).map(|(i,j)|i.max(j)).collect()
which has the much more reasonable type of
fn(&str, &str) -> String
Go, 131 121 bytes
func f(a,b string)(o string){
if""==a||b==""{o=""}else{A,B:=a[:1],b[:1]
if A>B{o+=A}else{o+=B}
o+=f(a[1:],b[1:])}
return}
- -10 by @The Thonnu
Thunno 2, 3 bytes
Z€G
Output as a list of characters. Add the J flag if you want a string.
Explanation
Z€G # Implicit input
Z # Zip the two inputs together
€ # For each pair:
G # Get the maximum of the pair
# Implicit output
Screenshot
C (gcc), 51 bytes
f(char*s,char*t){(*s=*s>*t|!*s?*s:*t)&&f(s+1,t+1);}
C (gcc), 51 bytes
f(char*s,char*t){(*s=0u-*s<-*t?*s:*t)&&f(s+1,t+1);}
Python 3, 26 bytes
lambda*a:list(map(max,*a))
Similar to another Python 3 answer, only that I use list instead of ''.join, which shaves 3 bytes off.
Thunno J B, \$ 5 \log_{256}(96) \approx \$ 4.12 bytes
ZZeMC
(No ATO link since it's not on a new enough version)
Explanation
ZZeMC # Implicit input. The B flag converts the strings to codepoints.
ZZe # Zip together and loop through:
M # Get the maximum
C # And get chr of that
# Implicit output, with the J flag joining everything together
Thunno J, \$ 9 \log_{256}(96) \approx \$ 7.41 bytes
ZZeO.AJMC
(No ATO link since it's not on a new enough version)
Explanation
Unfortunately the max command (M) doesn't work with strings, otherwise this would have been a lot simpler.
ZZeO.AJMC # Implicit input
ZZe # Zip together and loop through:
O.AJ # Get the ordinals of both characters
M # Get the maximum
C # And get chr of that
# Implicit output, with the J flag joining everything together
Screenshots
Knight, 70 51 48 bytes
;=aP;=bP W&a b;O+A I>a bAaAb"\";=aGa 1La=bGb 1Lb
Ungolfed & explained:
; = a PROMPT # a = input()
; = b PROMPT # b = input()
: WHILE & a b # while a != "" and b != "":
; OUTPUT + ASCII IF > a b ASCII #
a ASCII b "\" # print(a[0] if a > b else a[1]) # (without newline)
; = a GET a 1 LENGTH a # a = a[1:]
: = b GET b 1 LENGTH b # b = b[1:]
-19 bytes thanks to Adam.
-3 bytes thanks to Bubbler.
Vyxal, 3 bytes
ZvG
That is: the maximum function (G) vectorised over the inputs Zipped together (abc and def turn into [["a", "d"], ["b", "e"], ["c", "f"]]. Takes a single string (alternatively, a list of characters) and outputs a list of characters.
Excel, 86 bytes
=LET(x,SEQUENCE(MIN(LEN(A1),LEN(A2))),d,MID(A1,x,1),e,MID(A2,x,1),CONCAT(IF(d>e,d,e)))
05AB1E, 3 bytes
ø€à
ø€à # full program
ø # list of...
à # maximums of...
€ # each element of...
ø # code points of...
# implicit input...
ø # with each element paired with the corresponding element in second sub-list
# implicit output
Perl 5 -lF, 88 67 bytes
@b=<>=~/./g;$#F=$#b=@F>@b?$#b:$#F;say map{($q=shift@b)gt$_?$q:$_}@F
Japt, 9 bytes
Can't seem to do better than 9. Takes input as a 2D array of characters, outputs an array of characters
ñÊÕfÎËñ Ì
Try it (header formats the input)
ñÊÕfÎËñ Ì :Implicit input of 2D array
ñ :Sort by
Ê : Length
Õ :Transpose, padding the shorter array with null if necessary
f :Filter by
Î : First element (removing the arrays that contain null)
Ë :Map
ñ : Sort
Ì : Last element
Erlang (escript), 46 bytes
t([I|M],[E|S])->[max(I,E)]++t(M,S);t(_,_)->[].
Explanation
t([I|M],[E|S])-> % Extract the head of both operands
[max(I,E)] % Take the max of the heads
++t(M,S); % Recurse with the remaining strings
t(_,_) % If head-extraction fails for either of these operands:
->[]. % Return the empty string
Burlesque, 9 bytes
lnp^q>]Z[
Returns a list of characters add 2 bytes for concat (\[)
ln # Split on newlines
p^ # Push to arr
q>] # Boxed maximum
Z[ # ZipWith
Java 8, 124 120 117 63 bytes
a->b->{for(int i=0;;i++)System.out.print(a[i]>b[i]?a[i]:b[i]);}
-4 bytes thanks to @Khaled.K.
-3 bytes thanks to @Jakob.
Inputs are two character-arrays, and it stops with an ArrayIndexOutOfBoundsException.
Explanation:
a->b->{ // Method with two char-array parameters and no return-type
for(int i=0;;i++) // Loop `i` from 0 up indefinitely (until an error is given)
System.out.print( // Print:
a[i]>b[i]?a[i]:b[i]);} // The character that has the highest unicode value
R, 96 bytes
for(i in 1:min(lengths(m<-sapply(scan(,""),utf8ToInt))))cat(intToUtf8(max(m[[1]][i],m[[2]][i])))
Using ASCII code.
Cjam, 3 bytes
This is so easy...
.e>
Pretty much the same as the Haskell answer, . takes an operator and performs "zipWith", and e> means take the max of the two inputs.
Japt v2.0a0, 13 bytes
ÊmVl)îUcÈwVcY
Unpacked & How it works
Ul mVl)îUcXYZ{XwVcY
Ul Length of 1st input (U)
mVl) Minimum of above and length of 2nd input (V)
î Take this length out of the following string...
UcXYZ{ Map on charcodes of U and convert back to string...
Xw Maximum of this and...
VcY V's charcode at the same index.
Japt doesn't have min/max on strings, but does have one on numbers. Turns out that it helped reduce bytes on both "Compute minimum length of two strings" and "Map on two strings to take higher chars".
Add++, 8 bytes
D,f,@@,^
In versions 0.4 through 1.11, ^ exponents two numbers or "multiplies" two strings, depending on the type of the arguments.
Swift, 66 bytes
func f(a:String,b:String){print(String(zip(a,b).map{max($0,$1)}))}
Straight forward solution
Java, 158 151 bytes
Golfed:
String s(String a,String b){String r="";for(int i=0;i<Math.min(a.length(),b.length());i++){char c=a.charAt(i);char d=b.charAt(i);r+=c>d?c:d;}return r;}
Ungolfed:
String s(String a,String b) {
String r = "";
for(int i=0; i < Math.min(a.length(),b.length()); i++) {
char c = a.charAt(i);
char d = b.charAt(i);
r += c > d ? c : d; //absolute ternary abuse
}
return r;
}
Takes two strings in a and b.
Whispers, 49 bytes
> Input
> Input
>> L»R
>> Each 3 1 2
>> Output 4
How it works
Each line consists of (line no.) (> or >>) (command) (the line numbers are implicitly added in the actual program)
1 > Input - Retrieve the first input
2 > Input - Retrieve the second input
3 >> » - Take the maximum of...
L - the left argument and...
R - the right argument
4 >> Each - For each value in...
1 - the first line zipped with...
2 - the second input,
3 - call the third line
5 >> 4 - Run the fourth line, then...
Output - Output the result
Axiom, 67 20 bytes
f(a,b)==map(max,a,b)
And with this we now surpass JavaScript, Lisp until perhaps J and APL too.
The previous solution:
f(a,b)==concat[max(a.x,b.y)::String for x in 1..#a for y in 1..#b]
Acc!!, 186 bytes
N
Count i while _/128^i/32 {
_+128^(i+1)*N
}
_*128+N
Count i while _%128/32*(_/4096) {
Count j while _/128%128/(_%128+1) {
_/128^2*128^2+_/128%128+_%128*128
}
Write _%128
_/128^2*128+N
}
Input strings should be given on stdin, newline-separated. Try it online!
Explanation
We conceptually partition the accumulator into 7-bit registers, each of which can hold an input character. The first Count i loops until the input's ASCII code is smaller than 32, storing the first line of input into the accumulator, with the first character in the least-significant position:
, o l l e h
5 4 3 2 1 0
Accumulator value = asc(h) + 128*asc(e) + 128^2*asc(l) + ... = 1541853098728
Next, we shift everything left by one register, read the first character of the second line, and store it into register 0:
, o l l e h w
6 5 4 3 2 1 0
We Count i again while register 0 (_%128) and register 1 (_/128%128, though the formula can be golfed a bit in this context) are both >= 32. Inside the loop, we use a nested Count j loop to check if register 1 is strictly greater than register 0. (Comparisons are done via integer division: if a/(b+1) is 0, then a<=b; if a/(b+1) is nonzero, then a>b.) If it is greater, we swap the registers' contents. This loop executes at most once, because after swapping, the condition is guaranteed not to be true anymore.
After the (potential) swap, the larger of the two characters is in register 0, which we output. We then shift two registers to the right (_/128^2), shift one register back to the left (*128), and store the next input character in register 0 (+N):
, o l l e o
5 4 3 2 1 0
The Count i loop exits once one or both strings reach the newline at their end.
Pip, 9 bytes
DQSS_MaZb
Pip doesn't have a string max operator, so I used SS (Sort String) instead:
aZb Zip the two cmdline args together, truncating to shorter length
M To that list of 2-element lists of characters, map a function:
SS_ Sort each pair of characters stringwise
DQ and dequeue the second (larger) one
Autoprint the resulting list of characters
JavaScript (ES6), 47 45 bytes
f=
(a,b)=>a.replace(/./g,(c,i)=>c>b[i]?c:[b[i]])
<div oninput=o.textContent=f(a.value,b.value)><input id=a><input id=b><pre id=o>
Conveniently c>b[i] returns false past the end of b. Edit: Saved 2 bytes thanks to @ETHproductions.
Java 8 + Eclipse Collections, 70 64 bytes
a->b->a.zip(b).collect(p->(char)Math.max(p.getOne(),p.getTwo()))
a and b are both MutableList<Character> from eclipse collections.
Kotlin, 50 41 37 bytes
-9 bytes with function reference syntax -4 bytes with extension function
fun String.x(o:String)=zip(o,::maxOf)
If s, and x are in scope, and not in a function, this method is only 16 bytes
s.zip(x,::maxOf)
J, 25 bytes
>./&.(a.&i.)@(<.&#{."1,:)
explanation
half the bytes go to solving ensuring both inputs have the shorter inputs length (would love to see an improvement on this portion, if anyone has one):
(<.&#{."1,:)
<.&# is the minimum of the two lengths, and {."1,: takes that many characters from both rows of the 2-row table consisting of the left string stacked on top of the right one.
>./&.(a.&i.)
Use the Under verb &. to convert each character to its ascii index, take the maximum of the two numbers, and then convert back to characters.
Husk, 2 bytes
z▲
"Ungolfed"/Explained
Makes use of zip f that truncates the shorter list such that there are always two arguments for f, e.g. zip f [1,2] [3,4,5] == zip f [1,2] [3,4] == [f 1 3, f 2 4]:
z -- zip the implicit lists A,B with - e.g. "ab" "bcd" (lists of characters)
▲ -- maximum - [max 'a' 'b', max 'b' 'c']
-- implicitly print the result - "bc"
J, 22 bytes
0({"1\:~@,"0/)<.&#$&>;
Explanation
0({"1\:~@,"0/)<.&#$&>; Input: string x (LHS), string y (RHS)
# Get length of x and y
<.& Minimum of those
; Link x and y as a pair of boxed strings
$&> Shape each to the minimum length
,"0/ Reduce by joining elementwise
\:~@ Grade down each pair
0 {"1 Select the value at index 0 from each
Charcoal, 17 bytes
F⌊⟦LθLη⟧⌈⟦§θι§ηι⟧
Try it online! Link is to verbose version of code. Edit: Slice got added a few days later, which would have allowed the following code for 15 bytes: Try it online!
↑E✂θ⁰Lη¹⌈⟦ι§ηκ⟧
Retina, 55 36 bytes
^
¶
{O`¶.*
}`¶.(.*)¶(.)
$2¶$1¶
1!`.*
Try it online! Explanation: A line is prefixed to hold the result. While both strings still have characters left the inputs are sorted and the leading character with the highest code point is moved to the result while the other leading character is deleted. Finally the result is printed.
k, 14 bytes
{|/(&/#:'x)$'x}
Examples:
k)F:{|/(&/#:'x)$'x}
k)F("hello,";"world!")
"worlo,"
q translation:
{max(min count each x)$/:x}
Free interpreter available here
Modern Pascal
version 1 of algorithm (func:139bytes)
for var l:=1 to min(length(paramstr(1)),length(paramstr(2))) do
result+=iif(paramstr(1)[l]>paramstr(b)[l],paramstr(1)[l],paramstr(2)[l]);
Explanation The for loop is designed to crawl to the length of the shortest string. The output is compared appending to result the highest ASCII value of each letter crawled. Since we are using shortest length, we can access the strings elements directly - see v2 below, uses Copy() to be safer.
version 2 of algorithm (func:166bytes)
for var l:=1 to max(length(paramstr(1)),length(paramstr(2))) do
result+=iif(copy(paramstr(1),l,1)>copy(paramstr(2),l,1),copy(paramstr(1),l,1),copy(paramstr(2),l,1));
// Author of Modern Pascal
Javascript (ES2015), 66 63 49 bytes
a=>b=>[...a].map((c,i)=>c>b[i]?c:b[i]||'').join``
Explanation:
a=>b=> // Function with two string parameters
[...a] // Split a into array of characters
.map((c, i) => // Iterate over array
c>b[i] ? c : b[i]||'') // Use the character with the larger unicode value until the end of the larger string
.join`` // Join the array into a string
Previous Versions:
//ES2015
a=>b=>[...a].map((c,i)=>c>b[i]?c:b[i]).slice(0,b.length).join`` //63
a=>b=>a.split``.map((c,i)=>c>b[i]?c:b[i]).slice(0,b.length).join`` //66
a=>b=>a.split``.map((c,i)=>c>b[i]?c:b[i]).slice(0,Math.min(a.length,b.length)).join`` //85
a=>b=>{for(i=-1,c='';++i<Math.min(a.length,b.length);)c+=a[i]>b[i]?a[i]:b[i];return c} //86
a=>b=>{for(i=-1,c='';++i<Math.min(a.length,b.length);)c+=a[d='charCodeAt'](i)>b[d](i)?a[i]:b[i];return c} //105
a=>b=>a.split``.map((c,i)=>c[d='charCodeAt']()>b[d](i)?c:b[i]).slice(0,Math.min(a.length,b.length)).join`` //106
//With array comprehensions
a=>b=>[for(i of a.split``.map((c,i)=>c>b[i]?c:b[i]))i].slice(0,b.length).join`` //79
a=>b=>[for(i of a.split``.map((c,i)=>c>b[i]?c:b[i]))i].slice(0,Math.min(a.length,b.length)).join`` //98
a=>b=>[for(i of ' '.repeat(Math.min(a.length,b.length)).split``.map((_,i)=>a[i]>b[i]?a[i]:b[i]))i].join`` //105
a=>b=>[for(i of Array.apply(0,Array(Math.min(a.length,b.length))).map((_,i)=>a[i]>b[i]?a[i]:b[i]))i].join`` //107
a=>b=>[for(i of a.split``.map((c,i)=>c[d='charCodeAt']()>b[d](i)?c:b[i]))i].slice(0,Math.min(a.length,b.length)).join`` //119
a=>b=>[for(i of ' '.repeat(Math.min(a.length,b.length)).split``.map((_,i)=>a[d='charCodeAt'](i)>b[d](i)?a[i]:b[i]))i].join`` //124
a=>b=>[for(i of Array.apply(0,Array(Math.min(a.length,b.length))).map((_,i)=>a[d='charCodeAt'](i)>b[d](i)?a[i]:b[i]))i].join`` //127
Julia 0.5, 33 bytes
Pretty much the same concept as Python2, but shorter.
a->join(map(maximum,(zip(a...))))
V, 28, 24, 21 bytes
Í./&ò
dd{JdêHPÎúúx
Íî
Hexdump:
00000000: cd2e 2f26 f20a 6464 7b4a 64ea 4850 cefa ../&..dd{Jd.HP..
00000010: fa78 0acd ee .x...
Three bytes saved thanks to @nmjcman101!
Explanation:
Í " Globally substitute:
. " Any character
/ " With:
& " That character
ò " And a newline
dd " Delete this line
{ " Move to the first empty line
J " Delete this line
dê " Columnwise delete the second word
HP " Move to the first line, and paste the column we just deleted
Î " On every line:
úú " Sort the line by ASCII value
x " And delete the first character
Í " Remove all:
î " Newlines
Python 2, 47 44 34 bytes
-3 bytes thanks to musicman523. -10 bytes thanks to Blender.
Takes input as a list of strings.
lambda a:''.join(map(max,zip(*a)))
Aceto, 43 bytes
]w(x^
o|p
d(
do
X0l)x
`=`X(
€(=0p
rr€l<
Explanation:
First, we read the first string, and explode it, then we move a stack to the left, read the second string, and explode it:
€(
rr€
Now, we check for emptiness of either of the stacks and exit if that is the case:
X0l)
`=`X
=0
l
Next, we duplicate the top letter of both stacks, and convert them to code points, then move them both (and us) on the right stack:
]
o
d(
do
The w tests if something is less or equal. If so, we get mirrored to the right. Otherwise, we print the top letter, go on the left stack, drop the top element (the other letter) and move up (^), which moves us on the bottom <, which moves us back to the length check.
w(x^
|p
If however, the test was truthy, we get mirrored into the emptiness on the right, and we need to do the opposite. Eventually we reach the three commands that now drop, then move to the left stack and print its top element. The < is the same symbol we land on in the other case, so here too we are lead back to the length check.
x
(
p
<
This repeats until one of the length checks succeeds, i.e. if one of the input strings is exhausted.
JavaScript (ES6), 47 bytes
f=([S,...s],[T,...t])=>S&&T?(S>T?S:T)+f(s,t):''
A recursive solution, which walks the string, always outputting the largest character.
Snippet:
f=([S,...s],[T,...t])=>S&&T?(S>T?S:T)+f(s,t):''
console.log(f('programming puzzles & code golf!?','not yet graduated, needs a rehaul'));
console.log(f('king','object'));
console.log(f('blended','bold'));
console.log(f('lab0ur win.','the "super bowl"'));
console.log(f('donald j.','trumfefe!'));
C, 58 bytes
f(char*s,char*t){putchar(*s>*t?*s:*t);*++s&&*++t&&f(s,t);}
- -8 bytes @Steadybox
Retina, 28 bytes
{O^`
G`.
^.+$
M!\*`^.
Rm`^.
Explanation
{O^`
The { tells Retina to run the entire program in a loop until it fails to change the working string. O makes this a sorting stage which sorts non-empty lines by default. The ^ option reverses the result. So in effect, we get a reverse sort of the two lines if they're non-empty, putting the line with the larger leading character at the top.
G`.
Discard empty lines if there are any.
^.*$
If only one line is left, one of the lines was empty, and we remove the other one as well to stop the process.
M!\*`^.
Lots of configuration going on here. This matches (M) the first character in the working string (^.), returns it (!), prints it without a trailing linefeed (\) and then reverts the working string to its previous value (*). In other words, we simply print the first character of the working string (which is the maximal leading character) without actually changing the string.
Rm`^.
Finally, we remove the first character from each line, so that the next iteration processes the next character.
C#, 71, 67 bytes
saved a few bytes by using string.Join() instead of new string()
added 18 bytes to both versions for needing using System.Linq;
67 bytes
(a,b)=>string.Join("",(a.Zip(b,(x,y)=>x>y?x:y)));
71 bytes:
(a,b)=>new string(a.Zip(b,(x,y)=>x>y?x:y).ToArray());
Alice, 8 bytes
/oI\
@m+
Explanation
Alice also has this operator (which I called superimpose) but it doesn't limit the output to the shorter string's length (instead, the remaining characters of the longer string are appended). However, it also has an operator to truncate the longer of two strings to the length of the shorter one.
/ Reflect to SE, switch to Ordinal. The IP bounces diagonally up and down
through the code.
m Truncate, doesn't really do anything right now.
I Read a line of input.
The IP bounces off the bottom right corner and turns around.
I Read another line of input.
m Truncate the longer of the two input lines to the length of the shorter.
+ Superimpose: compute their elementwise maximum.
o Output the result.
@ Terminate the program.
Micro, 119 bytes
{R b i m+:R}:X{R a i m+:R}:Y
""\\:a:b:R
{b:M}:N
a:M
b a<if(N,)
0:i{i1+:i
a i m C b i m C~:> if(X,Y)
i M=if(,Z)}:Z
Z
R:\
R, 103 bytes
Code:
n=min(sapply(y<-strsplit(scan(,"",sep="\n"),""),length));cat(mapply(max,el(y)[1:n],y[[2]][1:n]),sep="")
Test cases:
> n=min(sapply(y<-strsplit(scan(,"",sep="\n"),""),length));cat(mapply(max,el(y)[1:n],y[[2]][1:n]),sep="")
1: programming puzzles & code golf!?
2: not yet graduated, needs a rehaul
3:
Read 2 items
prtgretmirgduuzzlesneedsde rolful
> x <- scan(,"",sep=NULL)
1: asd asd
3:
Read 2 items
> n=min(sapply(y<-strsplit(scan(,"",sep="\n"),""),length));cat(mapply(max,el(y)[1:n],y[[2]][1:n]),sep="")
1: king
2: object
3:
Read 2 items
oing
> n=min(sapply(y<-strsplit(scan(,"",sep="\n"),""),length));cat(mapply(max,el(y)[1:n],y[[2]][1:n]),sep="")
1: lab0ur win.
2: the "super bowl"
3:
Read 2 items
the0usuwir.
APL (Dyalog), 22 bytes
Takes two (or more!) strings as right argument.
{⎕UCS⌈⌿⎕UCS↑⍵↑¨⍨⌊/≢¨⍵}
{ an anonymous function where the right argument is represented by ⍵
⎕UCS the symbols from the Unicode Character Set which correspond to the
⌈⌿ maximum value in each column of
⎕UCS the code points from the Unicode Character Set for the
↑ matrified (matrix from list of strings)
⍵ arguments
↑¨⍨ each capped at the
⌊/ minimum of
≢¨ the lengths
⍵ of the arguments
}
MATL, 8 bytes
otX>cwA)
Input is a cell array of strings, in the format {'abcd' 'efg'}
As an aside, this also works for more than two strings.
Explanation
Consider input {'blended' 'bold'}. The stack is shown upside down, with more recent elements below.
o % Implicitly input a cell array of strongs. Convert to numeric
% vector of code points. This right-pads with zeros if needed
% STACK: [98 108 101 110 100 101 100;
98 111 108 100 0 0 0]
tX> % Duplicate. Maximum of each column
% STACK: [98 108 101 110 100 101 100;
98 111 108 100 0 0 0],
[98 111 108 110 100 101 100]
c % Convert to char
% STACK: [98 108 101 110 100 101 100;
98 111 108 100 0 0 0],
'bolnded'
w % Swap
% STACK: 'bolnded'
[98 108 101 110 100 101 100;
98 111 108 100 0 0 0]
A % All: gives true (shown as 1) for columns containing only nonzeros
% STACK: 'bolnded'
[1 1 1 1 0 0 0]
) % Use as logical index (mask). Implicitly display
% STACK: 'boln'
C#, 81 78 bytes
a=>b=>{var s="";try{for(int q=0;;q++)s+=a[q]>b[q]?a[q]:b[q];}catch{}return s;}
C# has implicit char to int conversion (because a char is actually an int underneath) which is nice, and instead of looking for shortest string just try until failure
PHP>=7.1, 52 Bytes
for(;$t=min(~$argv[1][$i],~$argv[2][$i++]);)echo~$t;
PHP>=7.1, 69 Bytes
for([,$a,$b]=$argv;(~$c=$a[$i])&&~$d=$b[$i++];)$r.=max($c,$d);;echo$r;
PHP>=7.1, 70 Bytes
for([,$a,$b]=$argv;(~$c=$a[$i])&&~$d=$b[$i++];)$r.=$c>$d?$c:$d;echo$r;
Clojure, 31 bytes
#(map(comp last sort list)% %2)
Yay for function composition :) Returns a sequence of characters instead of a string, but they mostly work the same way in Clojure except when printing or regex matching.
Sadly max does not work with characters.
PowerShell, 75 bytes
-join(1..(($a,$b=$args)|sort l*)[0].length|%{(,$a[$_-1],$b[$_-1]|sort)[1]})
# ^input array unpack
# ^string index generation offset by 1
# ^sort by length property, so output length matches shorter input
# ^loop over indices
# max of the two characters^
# ^output join
Save as .ps1 file and run
PS C:\> .\Get-MultipliedString.ps1 'hello,' 'world!'
worlo,
Previously, 78 bytes:
$i=0;-join$(while(($a=$args[0][$i])-and($b=$args[1][$i++])){($a,$b)[$b-gt$a]})
CJam, 12 bytes
q~z{1/~e>o}%
Input is a list of two strings. The program exits with an error (after producing the right output) if the two strings have different lengths.
Explanation
q~ e# Read input and evaluate
z e# Zip: list of strings of length 2, or 1 if one string is shorter
{ }% e# Map this block over list
1/ e# Split the string into array of (1 or 2) chars
~ e# Dump the chars onto the stack
e> e# Maximum of two chars. Error if there is only one char
o e# Output immediately, in case the program will error
Jelly, 5 bytes
żœ-"«
How it works
żœ-"« Main link. Arguemts: s, t (strings)
ż Zipwith; form all pairs of corresponding characters from s and t.
If one of the strings is longer than the other, its extra characters are
appended to the array of pairs.
« Dyadic minimum; get all minima of corresponding characters.
This yields the characters themselves for unmatched characters.
œ-" Zipwith multiset subtraction; remove a single occurrence of the minimum from
each character pair/singleton.
This yields the maximum for pairs, but an empty string for singletons.
Example
Let s = blended and t = bold.
ż yields ["bb", "lo", "el", "nd", 'd', 'e', 'd']. The last three elements are characters.
« is the vectorizing, dyadic minimum, so it yields ['b', 'l', 'e', 'd', 'd', 'e', 'd'].
œ-" removes exactly one occurrence of the nth character in the second array from the nth string/character in the first array, yielding ["b", "o", "l", "n", "", "", ""]. œ- is the multiset subtraction atom, and the quick " makes it vectorize.
When printed, this simply reads boln.
Mathematica, 78 bytes
FromCharacterCode[Max/@Thread[#~Take~Min[Length/@x]&/@(x=ToCharacterCode@#)]]&
There is another answer in Mathematica already. This answer take input as a list of strings, so /@ can be used on # instead of {##}. And we can just Map the long function name on object instead of assigning it to variables. (in fact, each Mathematica built-in symbol name is used at most once in the function)
Japt, 16 bytes
ñl g îUy ®¬ñ oÃq
Test it online! Takes input as an array of two strings.
Lack of min and max built-ins hurt Japt here, but it still manages to pull off a somewhat decent score...
Explanation
ñl g îUy ® ¬ ñ oà q
Uñl g îUy mZ{Zq ñ o} q
// Implicit: U = input array ["object", "king"]
Uy // Transpose the strings of U. ["ok", "bi", "jn", "eg", "c ", "t "]
mZ{ } // Map each string Z to
Zq ñ o // the larger of the two chars. (Literally Z.split().sort().pop())
// ["o", "i", "n", "g", "c", "t"]
q // Join into a single string. "oingct"
Uñl g // Sort the two input strings by length and take the shorter.
î // Trim the previous result to this length.
// "king"î"oingct" -> "oing"
// Implicit: output result of last expression
Mathematica, 102 bytes
T=ToCharacterCode;L=Length;(a=T@#;b=T@#2;FromCharacterCode@Table[Max[a[[i]],b[[i]]],{i,L@a~Min~L@b}])&
input
["blended ", "bold"]
Perl 6, 22 bytes
{[~] [Zmax] @_».comb}
As a bonus, it accepts any number of multiplicands, not just two.


