Largest int from concatenated ints: Difference between revisions

Content added Content deleted
(Add Nimrod)
(jq)
Line 541: Line 541:
<pre>998764543431
<pre>998764543431
6054854654</pre>
6054854654</pre>

=={{header|jq}}==
{{Works with|jq|1.4}}
For jq versions greater than 1.4, it may be necessary to change "sort_by" to "sort".

The following uses the padding technique.
<lang jq>def largest_int:

def pad(n): . + (n - length) * .[length-1:];

map(tostring)
| (map(length) | max) as $max
| map([., pad($max)])
| sort_by( .[1] )
| map( .[0] ) | reverse | join("") ;

# Examples:
([1, 34, 3, 98, 9, 76, 45, 4],
[54, 546, 548, 60]) | largest_int
</lang>
{{Out}}
$ /usr/local/bin/jq -n -M -r -f Largest_int_from_concatenated_ints.jq
998764543431
6054854654


=={{header|Lua}}==
=={{header|Lua}}==