Largest int from concatenated ints: Difference between revisions

Content added Content deleted
m (→‎{{header|REXX}}: added/changed whitespace and comments, simplified an expression.)
(→‎{{header|Kotlin}}: Update Kotlin)
Line 741: Line 741:
=={{header|Kotlin}}==
=={{header|Kotlin}}==
{{trans|C#}}
{{trans|C#}}
{{works with|Kotlin|M12}}
{{works with|Kotlin|1.0b4}}
<lang kotlin>import java.util.Comparator
<lang kotlin>import java.util.Comparator


Line 747: Line 747:
val xy = (x.toString() + y).toInt()
val xy = (x.toString() + y).toInt()
val yx = (y.toString() + x).toInt()
val yx = (y.toString() + x).toInt()
return@Comparator xy.compareTo(yx)
xy.compareTo(yx)
}
}


fun maxCat() {
fun maxCat() {
fun findLargestSequence(array: Array<Int>): String {
fun findLargestSequence(array: IntArray): String {
return array.sortBy(SORTER).reverse().map { it.toString() }.join(separator = "")
return array.sortedWith(SORTER).reversed().map { it.toString() }.joinToString("")
}
} // Not using specialized IntArray as it does not have sortBy
val source1 = intArrayOf(1, 34, 3, 98, 9, 76, 45, 4)

val source1 = arrayOf(1, 34, 3, 98, 9, 76, 45, 4)
println(findLargestSequence(source1))
println(findLargestSequence(source1))


val source2 = arrayOf(54, 546, 548, 60);
val source2 = intArrayOf(54, 546, 548, 60);
println(findLargestSequence(source2))
println(findLargestSequence(source2))
}</lang>
}</lang>