aboutsummaryrefslogtreecommitdiff
path: root/scripts/sleepsort
blob: ea20fcb1b596580796aa28ac6cf7086e6d3ad756 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#!/usr/bin/env bash

# Taken from:
# https://www.quora.com/What-is-the-strangest-sorting-algorithm/answer/Nipun-Ramakrishnan

function f() {
    sleep "$1"
    echo "$1"
}

while [ -n "$1" ]
do
    f "$1" &
    shift
done

wait

# example usage:
# sleepsort 5 3 6 3 6 3 1 4 7