Sleep Sort in Powershell

Published on 05 July 2025 (Updated: 05 July 2025)

Welcome to the Sleep Sort in Powershell page! Here, you'll find the source code for this program as well as a description of how the program works.

Current Solution

function Show-Usage() {
    Write-Host 'Usage: please provide a list of at least two integers to sort in the format "1, 2, 3, 4, 5"'
    Exit 1
}

function Parse-IntList([string]$Str) {
    @($Str.Split(",") | ForEach-Object { [int]::Parse($_) })
}

function Invoke-SleepSort([int[]]$Values) {
    @($Values | ForEach-Object -Parallel {
        Start-Sleep $_
        $_
    } -ThrottleLimit $Values.Length)
}

if ($args.Length -lt 1) {
    Show-Usage
}

try {
    $values = Parse-IntList $args[0]
    if ($values.Length -lt 2) {
        Show-Usage
    }
} catch {
    Show-Usage
}

$sortedValues = Invoke-SleepSort $values
Write-Host ($sortedValues -join ', ')

Sleep Sort in Powershell was written by:

If you see anything you'd like to change or update, please consider contributing.

How to Implement the Solution

No 'How to Implement the Solution' section available. Please consider contributing.

How to Run the Solution

No 'How to Run the Solution' section available. Please consider contributing.