A Collection of Code Snippets in as Many Programming Languages as Possible
This project is maintained by TheRenegadeCoder
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.
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.
No 'How to Implement the Solution' section available. Please consider contributing.
No 'How to Run the Solution' section available. Please consider contributing.