| Bytes | Lang | Time | Link |
|---|---|---|---|
| 003 | Japt | 250725T143852Z | Shaggy |
| 008 | Uiua | 240810T035137Z | ErikDaPa |
| 018 | Dyalog APL | 250724T235357Z | Aaron |
| 045 | AWK | 250304T200032Z | xrs |
| 144 | Tcl | 181115T190649Z | sergiol |
| 008 | Vyxal 3 | 240810T061022Z | bb94 |
| 001 | UiuaSBCS | 240809T074029Z | Europe20 |
| 001 | Thunno 2 | 230816T102457Z | The Thon |
| 045 | Knight | 220804T031928Z | naffetS |
| 004 | Factor | 220615T060110Z | chunes |
| 053 | Python 3 | 200918T041813Z | lukekh |
| 013 | Pip | 200912T062617Z | Razetime |
| 102 | APLNARS | 200103T090224Z | user5898 |
| 022 | Perl 5 MListUtil=max F | 200101T233719Z | Xcali |
| 074 | Wren | 200101T141451Z | user8505 |
| 008 | Charcoal | 181115T200613Z | Neil |
| 039 | Retina 0.8.2 | 181115T195353Z | Neil |
| 025 | Ruby | 181119T090906Z | G B |
| 057 | C# .NET Core | 181116T133045Z | LiefdeWe |
| 5599 | Ceylon | 181117T224704Z | Paŭlo Eb |
| 004 | Japt | 181116T182255Z | Oliver |
| 057 | Java 10 | 181116T084731Z | Kevin Cr |
| 015 | Perl 6 | 181116T023916Z | Jo King |
| 020 | Python 2 | 181115T151111Z | Erik the |
| 001 | Jelly | 181115T145449Z | Erik the |
| 125 | Twig | 181116T111421Z | Ismael M |
| 049 | JavaScript ES6 | 181115T161523Z | Arnauld |
| 002 | MATL | 181116T011744Z | Luis Men |
| 005 | Pyth | 181115T211338Z | lirtosia |
| 005 | 05AB1E | 181115T152318Z | Riley |
| 120 | Batch | 181115T202118Z | Neil |
| 153 | SNOBOL4 CSNOBOL4 | 181115T193317Z | Giuseppe |
| 037 | Perl 6 | 181115T190314Z | Sean |
| 005 | Stax | 181115T183806Z | recursiv |
| 040 | Haskell | 181115T181536Z | ბიმო |
| 065 | R | 181115T152019Z | Giuseppe |
| 007 | Japt | 181115T155006Z | Shaggy |
| 012 | J | 181115T152120Z | Galen Iv |
| 005 | Husk | 181115T180300Z | ბიმო |
| 056 | Python 2 | 181115T144830Z | TFeld |
Uiua, 14 8 bytes (thanks to nyxbird's suggestion)
⍜∩⊥₁₀⬚0↥
14 bytes version:
⋕/↥⬚⌞@ ⊟∩°⋕
Explanation:
⍜∩⊥₁₀⬚0↥
∩⊥₁₀ => convert to reversed list of digits
⬚0↥ => max between digits padded with 0s if needed
⍜ => then convert back into a number
⋕/↥⬚⌞@ ⊟∩°⋕
∩°⋕ => both numbers into strs
⬚⌞@ ⊟ => combine and pad 0s on the left
/↥ => find max between digits (ascii-wise)
⋕ => finally parse
Clarification: Input is two integer numbers, not strings.
Try this online! (8 bytes version)
Try this online! (14 bytes version)
Desmos, 43 / 95 bytes
Input is 2 lists of digits with the short one being pre-padded with 0s.
f(X,Y)=[max(X[i],Y[i])fori=[1...length(X)]] => maximum between each digit
95 bytes version: (input is 2 lists of digits, w/out pre-padding)
a=length(X) => redefinitions
b=length(Y)
n(x)=\{x=x:x,0\} => convert undef to 0
g(X,Y)=[max(n(X[a-i]),n(Y[b-i]))fori=[max(a,b)-1...0]] => maximum of each digit from the right-most digit
Dyalog APL, 18 chars
{10⊥⌈⌿⌽↑⌽¨⍎¨∘⍕¨⍺⍵}
Explanation:
{ }
⍕ Format (turn to string)
∘ and (compose)
⍎¨ execute each character to turn into a vector of digits
¨ On each
⍺⍵ of the left and right args
⌽¨ Reverse both of them
⌽↑ Mix and reverse again; this was done so that the
mixing would append zeroes to the front if
one number is fewer characters than the other
⌈⌿ Find the max of each column
10⊥ And turn it into a base-10 number again
Tcl, 144 bytes
proc S a\ b {join [lmap x [split [format %0[set l [string le [expr max($a,$b)]]]d $a] ""] y [split [format %0$l\d $b] ""] {expr max($x,$y)}] ""}
UiuaSBCS, 1 byte
↥
Input as two space-padded strings.
↥ maximum compares each pair of characters and puts the larger one in the new array.
Knight, 45 bytes
;=aP;=bP Wa;O+A I>a bAaAb"\";=aGa 1La=bGb 1Lb
Takes two zero-padded numbers (it works with spaces as well).
Python 3, 53 bytes
s=lambda p,q:p+q and 10*s(p//10,q//10)+max(p%10,q%10)
Pip, 13 bytes
{aGTb?ab}MZab
Maps zipped pairs of the two inputs and then returns the greater one.
Inputs must be padded with spaces.
APL(NARS), 51 chars, 102 bytes
{k←⌈/≢¨(a b)←⍎¨∘⍕¨⍺⍵⋄f←{((k-≢⍵)⍴0),⍵}⋄10⊥(f a)⌈f b}
test:
h←{k←⌈/≢¨(a b)←⍎¨∘⍕¨⍺⍵⋄f←{((k-≢⍵)⍴0),⍵}⋄10⊥(f a)⌈f b}
1999 h 2018
2999
17210 h 701
17711
32 h 17
37
308 h 250
358
308 h 25
328
Perl 5 -MList::Util=max -F, 22 bytes
say map{max $_,getc}@F
Input must be 0 or space padded so that the entries are the same length.
Wren, 74 bytes
Fn.new{|i|(0...i.count/2).map{|j|i[j]>i[j+i.count/2]?i[j]:i[j+i.count/2]}}
Input is a single list of the two operands, e.g.
[1, 7, 2, 1, 0,
0, 0, 7, 0, 1]
Explanation
Now I need to figure out a formula for maximum.
Fn.new{|i| } // New anonymous function with the operand i
(0...i.count/2) // Define an exclusive range from 0 to half the input
.map{|j| } // Turn every item of the list into ...
i[j]>i[j+i.count/2]?i[j]:i[j+i.count/2] // ... The maximum between i[j] and i[j+i.count/2]
// (which is simply the other list's index at the same position)
Charcoal, 8 bytes
⭆θ⌈⟦ι§ηκ
Try it online! Link is to verbose version of code. Explanation:
θ First input
⭆ Map over characters and join
⌈ Maximum of
⟦ List of
ι Current character of first input and
η Second input
§ Indexed by
κ Current index
Implicitly print
10-byte version "adds" any number of padded strings:
⭆§θ⁰⌈Eθ§λκ
Try it online! Link is to verbose version of code. Previous 14-byte version accepts unpadded strings:
⭆◧θLη⌈⟦ι§◧ηLθκ
Try it online! Link is to verbose version of code. Explanation:
θ First input
◧ Padded to
L Length of
η Second input
⭆ Map over characters and join
⌈ Maximum of
⟦ List of
ι Current character of first input and
η Second input
◧ Padded to
L Length of
θ First input
§ Indexed by
κ Current index
Implicitly print
17-byte version "adds" any number of strings:
≔⌈EθLιη⭆η⌈Eθ§◧ληκ
Try it online! Link is to verbose version of code.
Retina 0.8.2, 39 bytes
+`^(.*)(.)¶(.*)(.)
$1¶$3¶$2$4
%O`.
¶.?
Try it online! Link includes test suite. Previous 45-byte Retina 1 version accepts unpadded strings:
P^`.+
+`^(.*)(.)¶(.*)(.)
$1¶$3¶$2$4
%O`.
¶.?
Try it online! Link includes test suite. Explanation:
P^`.+
Pad both values to the same length. (Retina 1 only. There are ways of emulating this in Retina 0.8.2 but they are not very golfy.)
+`^(.*)(.)¶(.*)(.)
$1¶$3¶$2$4
Transpose the values.
%O`.
Sort each pair into order.
¶.?
Delete all the low digits and surplus newlines.
Ruby, 25 bytes
->a,b{a.zip(b).map &:max}
Pre-padded list blah blah. (Although it feels a little like cheating.)
Ceylon, 55 / 99
With 0- or space-padded strings of same length (returning an iterable of characters):
function t(String a,String b)=>zipPairs(a,b).map(max);
With 0- or space-padded strings (returning a String):
String t(String a,String b)=>String(zipPairs(a,b).map(max));
With strings of possibly different length (returning a String):
String u(String a,String b)=>String(zipPairs(a.padLeading(b.size),b.padLeading(a.size)).map(max));
Java 10, 78 57 bytes
a->b->{for(int i=a.length;i-->0;)if(a[i]<b[i])a[i]=b[i];}
Input as two space-padded character arrays.
Modifies the first input-array instead of returning a new one to save 21 bytes (thanks to @OlivierGrégoire).
Explanation:
a->b->{ // Method with two char-array parameters and String return-type
for(int i=a.length;i-->0;)
// Loop `i` in the range (length, 0]:
if(a[i]<b[i]) // If the `i`'th character in input `a` is smaller than in input `b`:
a[i]=b[i];} // Change the `i`'th character in `a` to the `i`'th character of `b`
Perl 6, 15 bytes
{[~] [Zmax] $_}
Takes input as a list of space padded arrays of characters, though for this challenge the lax input format makes it rather boring. Alternatively, here's the program that takes a list of two integers instead:
Perl 6, 41 bytes
{+[~] [Zmax] $_>>.fmt("%{.max}d")>>.comb}
If you don't mind a huge amount of whitespace, you can also remove the + from the front.
Explanation:
{ } # Anonymous code block
$_>> # Map each integer to
.fmt("%{.max}d") # The number padded by the max of the list spaces
>>.comb # And split each to list of characters
[Zmax] # Get the max of each digit at each index
# This works because space is coerced to 0
# Otherwise we would have to add a 0 to the formatting string
[~] # Join the list of digits and spaces
+ # And coerce the string to a number to get rid of leading whitespace
Twig, 125 bytes
When I saw this challenge, I though: "let me use a template language! sure is a good fit"
I was wrong ... so wrong .... ... But was fun!
{%macro a(a,b,s='')%}{%for k,x in a|reverse|split('')%}{%set s=max(x,(b|reverse|split('')[k]))~s%}{%endfor%}{{s}}{%endmacro%}
This requires that "strict_variables" is set to false (default value).
To use this macro, you can do like this:
{% import 'file.twig' as my_macro %}
{{ my_macro.a(195,67) }}
Should display 167.
You can try this in https://twigfiddle.com/rg0biy
("strict_variables" set to off, it is on by default on the website)
JavaScript (ES6), 51 49 bytes
NB: This answer was posted before the loose I/O formats were explicitly allowed. With zero-padded arrays of digits, this can be done in 33 bytes, (but is much less interesting, IMHO).
Takes input as two integers. Returns an integer.
f=(a,b,t=10)=>a|b&&(a%t<b%t?b:a)%t+t*f(a/t,b/t)|0
Commented
f = ( // f = recursive function taking:
a, // a = first integer
b, // b = second integer
t = 10 // t = 10 (which is used 6 times below)
) => //
a | b // bitwise OR between a and b to test whether at least one of
// them still has an integer part
&& // if not, stop recursion; otherwise:
( //
a % t < b % t ? b : a // if a % 10 is less than b % 10: use b; otherwise: use a
) % t + // isolate the last decimal digit of the selected number
t * // add 10 times the result of
f(a / t, b / t) // a recursive call with a / 10 and b / 10
| 0 // bitwise OR with 0 to isolate the integer part
Alternate version
Same I/O format.
f=(a,b)=>a|b&&[f(a/10,b/10)]+(a%10<b%10?b:a)%10|0
MATL, 2 bytes
X>
Choose the most appropriate format for your language/solution
The input format is: 2D char array of two rows, each corresponding to a line, with the shorter number left-padded with spaces. For example
17210
701
which in MATL is defined as
['17210'; ' 701']
Explanation
% Implicit input: 2D char array with two rows
X> % Take maximum of (code points of) each column
% Implicit display
Pyth, 5 bytes
meSdC
Takes input as array of two space-padded strings.
meSd map greatest
C on the transpose of input
Try it here.
05AB1E, 9 6 5 bytes
-3 thanks to Emigna
-1 thanks to Shaggy
íζ€àR
Takes input as a list of lists of digits
í # Reverse both inputs
ζ # Zip
ۈ # Keep the bigger digits
R # Reverse
Batch, 120 bytes
@set/aw=1,x=%1,y=%2,z=0
@for /l %%i in (0,1,9)do @set/a"z+=w*((v=y%%10)+(v-=x%%10)*(v>>4)),y/=10,x/=10,w*=10
@echo %z%
Takes input as command-line parameters. 188-byte version works on arbitrary length integers:
@set/px=
@set/py=
@set z=
:l
@if %x:~-1% gtr %y:~-1% (set z=%x:~-1%%z%)else set z=%y:~-1%%z%
@set x=%x:~,-1%
@set y=%y:~,-1%
@if "%x%" neq "" if "%y%" neq "" goto l
@echo %x%%y%%z%
Takes input on STDIN.
SNOBOL4 (CSNOBOL4), 153 bytes
X =INPUT
Y =INPUT
Y =DUPL(0,SIZE(X) - SIZE(Y)) Y
S X LEN(1) . A REM . X :F(O)
Y LEN(1) . B REM . Y
O =O GT(A,B) A :S(S)
O =O B :(S)
O OUTPUT =O
END
Stax, 5 bytes
|>E:o
This program takes input as an array of strings.
|> Right align inputs (filling with \0)
E "Explode" array onto stack separately
:o "Overlay" Keep the maximum element respective element from two arrays.
This is the first time I've seen a use for the overlay instruction "in the wild".
Haskell, 40 bytes
a#b=zipWith max(p b++a)$p a++b
p=(' '<$)
Input/output as strings, try it online!
Explanation
The function p replaces each character by a space, using p b++a and p a++b are thus the same length. This way we can use zipWith without losing any elements, using max with it works because a (space) has lower codepoint than any of the characters ['0'..'9'].
R, 68 65 bytes
function(x)apply(outer(x,10^(max(nchar(x)):1-1),`%/%`)%%10,2,max)
Input as integers, output as list of digits.
If zero-padding lists of digits was allowed, then simply pmax would suffice.
Japt, 9 8 7 bytes
Takes input as an array of digit arrays.
mÔÕÔËrw
m :Map
Ô : Reverse
Õ :Transpose
Ô :Reverse
Ë :Map
r : Reduce by
w : Maximum
If taking zero-padded arrays as input is permitted (it would currently fall under a "convenient format" but I suspect that's not the challenger's intent) then this can be 3 bytes.
íwV
í :Interleave the first input
V :With the second
w :Reduce each pair by maximum
Husk, 5 bytes
↔¤żY↔
Conveniently takes input/output as list of digits, try it online or verify all!
Explanation
↔¤żY↔ -- example inputs [1,4] [3,2]
¤ ↔ -- reverse the arguments of: [4,1] [2,3]
żY -- | zipWith (keeping elements of longer) max: [4,3]
↔ -- reverse: [3,4]
Python 2, 73 60 56 bytes
lambda a,b:map(max,zip(a.rjust(len(b)),b.rjust(len(a))))
Takes input as two strings, and returns a list of digits
Alternative:
Takes input as two integers; same output
Python 2, 60 59 bytes
lambda*i:map(max,zip(*['%*d'%(len(`max(i)`),v)for v in i]))