Largest int from concatenated ints
func maxnum(nums) {
nums.sort {|x,y| "#{y}#{x}" <=> "#{x}#{y}" };
}
[[54, 546, 548, 60], [1, 34, 3, 98, 9, 76, 45, 4]].each { |c|
say maxnum(c).join.to_num;
}
Output:
6054854654
998764543431
func maxnum(nums) {
nums.sort {|x,y| "#{y}#{x}" <=> "#{x}#{y}" };
}
[[54, 546, 548, 60], [1, 34, 3, 98, 9, 76, 45, 4]].each { |c|
say maxnum(c).join.to_num;
}
6054854654
998764543431