/**
 * This function takes a list of coordinates and sorts them based on their distance from the origin (0,0).
 */
fun sortCoordinates(coordinates: List<Pair<Int, Int>>): List<Pair<Int, Int>> {

    val sortedCoordinates = mutableListOf<Pair<Int, Int>>()
    val distances = mutableListOf<Double>()

    for (coord in coordinates) {
        val (x, y) = coord
        val distance = Math.sqrt((x * x + y * y).toDouble())
        distances.add(distance)
    }

    repeat(distances.size) {
        val minDistance = distances.minOrNull()!!
        val minIndex = distances.indexOf(minDistance)
        sortedCoordinates.add(coordinates[minIndex])
        distances.removeAt(minIndex)
        coordinates.toMutableList().removeAt(minIndex)
    }

    return sortedCoordinates
}
/**
 * This function takes a list of coordinates and sorts them based on their distance from the origin (0,0).
 */
fun sortCoordinates(coordinates: List<Pair<Int, Int>>): List<Pair<Int, Int>> {
/**
 * This function takes a list of coordinates and sorts them based on their distance from the origin (0,0).
 */
fun sortCoordinates(coordinates: List<Pair<Int, Int>>): List<Pair<Int, Int>> {

    val sortedCoordinates = mutableListOf<Pair<Int, Int>>()
    val distances = mutableListOf<Double>()

    for (coord in coordinates) {
        val (x, y) = coord
        val distance = Math.sqrt((x * x + y * y).toDouble())
        distances.add(distance)
    }

    repeat(distances.size) {
        val minDistance = distances.minOrNull()!!
        val minIndex = distances.indexOf(minDistance)
        sortedCoordinates.add(coordinates[minIndex])
        distances.removeAt(minIndex)
        coordinates.toMutableList().removeAt(minIndex)
    }

    return sortedCoordinates
}