Largest int from concatenated ints: Difference between revisions
Content added Content deleted
(+Java) |
|||
Line 198: | Line 198: | ||
=={{header|Ruby}}== |
=={{header|Ruby}}== |
||
===Sort on comparison of concatenated ints method=== |
|||
{{trans|Tcl}} |
{{trans|Tcl}} |
||
Line 215: | Line 216: | ||
[1, 34, 3, 98, 9, 76, 45, 4] |
[1, 34, 3, 98, 9, 76, 45, 4] |
||
998764543431</pre> |
998764543431</pre> |
||
===Compare repeated string method=== |
|||
<lang ruby>def icsort nums |
|||
maxlen = nums.max.to_s.length |
|||
nums.map{ |x| x.to_s }.sort_by { |x| x * (maxlen / x.length + 1) }.reverse |
|||
end |
|||
[[54, 546, 548, 60], [1, 34, 3, 98, 9, 76, 45, 4]].each do |c| |
|||
p c # prints nicer in Ruby 1.8 |
|||
puts icsort(c).join |
|||
end</lang> |
|||
;Output as above. |
|||
=={{header|Run BASIC}}== |
=={{header|Run BASIC}}== |