o3-2025-04-16· OpenAI
LMArena Human Preference 140K
Schreibe eine bubblesort Funktion in Kolton. Sie soll möglichst kurz sein
- User
Schreibe eine bubblesort Funktion in Kolton. Sie soll möglichst kurz sein
- Assistant
Hier kommt ein winziger, aber voll funktionsfähiger Bubble-Sort in Kotlin – so kompakt, dass er fast schon als One-Liner durchgeht:
kotlinfun <T : Comparable<T>> MutableList<T>.bubble() = apply { for (i in lastIndex downTo 1) for (j in 0 until i) if (this[j] > this[j + 1]) this[j + 1] = this[j].also { this[j] = it } }Benutzung:
kotlinval nums = mutableListOf(5, 2, 9, 1, 3) nums.bubble() println(nums) // -> [1, 2, 3, 5, 9]•
applygibt direkt die sortierte Liste zurück (praktisch fürs Chaining).
• Deralso-Trick erledigt den Swap ohne Extra-Variable.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.