// Selection sort benchmark - simpler sorting algorithm
fn selectionSort(size: Int): Int = {
    // Sort numbers using accumulator pattern
    sortLoop(size, 0, 0)
}

fn sortLoop(size: Int, i: Int, swaps: Int): Int = {
    if i >= size then swaps
    else {
        // Find minimum in remaining portion (simulated)
        let minIdx = findMin(i, size, i)
        let newSwaps = if minIdx != i then swaps + 1 else swaps
        sortLoop(size, i + 1, newSwaps)
    }
}

fn findMin(start: Int, end: Int, minIdx: Int): Int = {
    if start >= end then minIdx
    else {
        // Simulated comparison using modular arithmetic
        let curr = (start * 7 + 13) % 1000
        let minVal = (minIdx * 7 + 13) % 1000
        let newMin = if curr < minVal then start else minIdx
        findMin(start + 1, end, newMin)
    }
}

fn main(): Unit = {
    let swaps = selectionSort(1000)
    Console.print("Sort completed with " + toString(swaps) + " swaps")
}
