/**
 * Given a target position and a list of positions,
 * this function finds the position closest to the target.
 */
fun findNearestPosition(target: Int, positions: List<Int>): Int {

    var nearestPosition = positions[0]
    var nearestDistance = Math.abs(target - positions[0])

    for (position in positions.drop(1)) {
        val distance = Math.abs(target - position)
        if (distance < nearestDistance) {
            nearestPosition = position
            nearestDistance = distance
        }
    }

    return nearestPosition
}
/**
 * Given a target position and a list of positions,
 * this function finds the position closest to the target.
 */
fun findNearestPosition(target: Int, positions: List<Int>): Int {
/**
 * Given a target position and a list of positions,
 * this function finds the position closest to the target.
 */
fun findNearestPosition(target: Int, positions: List<Int>): Int {

    var nearestPosition = positions[0]
    var nearestDistance = Math.abs(target - positions[0])

    for (position in positions.drop(1)) {
        val distance = Math.abs(target - position)
        if (distance < nearestDistance) {
            nearestPosition = position
            nearestDistance = distance
        }
    }

    return nearestPosition
}