Genius Sleep Sort Algorithm
Genius sorting algorithm: Sleep sort 1 Name: Anonymous 2011-01-20 12:22 Man, am I a genius. Check out this sorting algorithm I just invented. #!/bin/bash function f() { sleep "$1" echo "$1" } while [ -n "$1" ] do f "$1" & shift done wait example usage: ./sleepsort.bash 5 3 6 3 6 3 1 4 7 The algorithm basically works like this: For every element x in an array, start a new program that: Sleeps for x seconds Prints out x The clock starts on all the elements at the same time. It works for any array that has non-negative numbers.
A screenshot presents the joke Bash algorithm “Sleep sort,” which launches a process for each number, waits for that many seconds, and prints the number afterward. The numbers therefore appear in ascending order because smaller values finish sleeping first. The punchline is that this absurdly slow and resource-heavy method is presented as a genius invention, making it a classic programming joke for developers. EN: A screenshot presents the joke Bash algorithm “Sleep sort,” which launches a process for each number, waits for that many seconds, and prints the number afterward. The numbers therefore appear in ascending order because smaller values finish sleeping first. The punchline is that this absurdly slow and resource-heavy method is presented as a genius invention, making it a classic programming joke for developers.
- @dev_meme / 1963 2020-08-25
- Template
- Sleep sort
- Type
- image
- Size
- 671×604 · 41.1 KiB
- Mood
- absurd, sarcastic
- Language
- en
- Added