/**
 * Given a list of tuples containing coordinates (latitude, longitude) of different locations,
 * remove all tuples which have the same latitude and longitude values as the given coordinate.
 * Then, append a new tuple with coordinates randomly generated.
 *
 * @param locations A list of tuples containing coordinates.
 * @param coordinate A tuple with a specific coordinate to remove from the list.
 * @return A modified list with duplicate coordinates removed and a new random coordinate appended.
 */
fun removeAndAppend(locations: MutableList<Pair<Double, Double>>, coordinate: Pair<Double, Double>): MutableList<Pair<Double, Double>> {

    // Remove all tuples with the same latitude and longitude as the given coordinate
    locations.removeIf { it == coordinate }

    // Generate a random latitude and longitude tuple
    val randomCoordinate = Pair(Math.random() * 180 - 90, Math.random() * 360 - 180)

    // Append the new random coordinate to the locations list
    locations.add(randomCoordinate)

    return locations
}

// Example Usage
/**
 * Given a list of tuples containing coordinates (latitude, longitude) of different locations,
 * remove all tuples which have the same latitude and longitude values as the given coordinate.
 * Then, append a new tuple with coordinates randomly generated.
 *
 * @param locations A list of tuples containing coordinates.
 * @param coordinate A tuple with a specific coordinate to remove from the list.
 * @return A modified list with duplicate coordinates removed and a new random coordinate appended.
 */
fun removeAndAppend(locations: MutableList<Pair<Double, Double>>, coordinate: Pair<Double, Double>): MutableList<Pair<Double, Double>> {
/**
 * Given a list of tuples containing coordinates (latitude, longitude) of different locations,
 * remove all tuples which have the same latitude and longitude values as the given coordinate.
 * Then, append a new tuple with coordinates randomly generated.
 *
 * @param locations A list of tuples containing coordinates.
 * @param coordinate A tuple with a specific coordinate to remove from the list.
 * @return A modified list with duplicate coordinates removed and a new random coordinate appended.
 */
fun removeAndAppend(locations: MutableList<Pair<Double, Double>>, coordinate: Pair<Double, Double>): MutableList<Pair<Double, Double>> {

    // Remove all tuples with the same latitude and longitude as the given coordinate
    locations.removeIf { it == coordinate }

    // Generate a random latitude and longitude tuple
    val randomCoordinate = Pair(Math.random() * 180 - 90, Math.random() * 360 - 180)

    // Append the new random coordinate to the locations list
    locations.add(randomCoordinate)

    return locations
}

// Example Usage