How to resolve the algorithm Sorting algorithms/Sleep sort step by step in the Common Lisp programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm Sorting algorithms/Sleep sort step by step in the Common Lisp programming language
Table of Contents
Problem Statement
In general, sleep sort works by starting a separate task for each item to be sorted, where each task sleeps for an interval corresponding to the item's sort key, then emits the item. Items are then collected sequentially in time. Task: Write a program that implements sleep sort. Have it accept non-negative integers on the command line and print the integers in sorted order. If this is not idomatic in your language or environment, input and output may be done differently. Enhancements for optimization, generalization, practicality, robustness, and so on are not required. Sleep sort was presented anonymously on 4chan and has been discussed on Hacker News.
Let's start with the solution:
Step by Step solution about How to resolve the algorithm Sorting algorithms/Sleep sort step by step in the Common Lisp programming language
Source code in the common programming language
(defun sleeprint(n)
(sleep (/ n 10))
(format t "~a~%" n))
(loop for arg in (cdr sb-ext:*posix-argv*) doing
(sb-thread:make-thread (lambda() (sleeprint (parse-integer arg)))))
(loop while (not (null (cdr (sb-thread:list-all-threads)))))
You may also check:How to resolve the algorithm Bitmap/Midpoint circle algorithm step by step in the zkl programming language
You may also check:How to resolve the algorithm Bitmap/Flood fill step by step in the BBC BASIC programming language
You may also check:How to resolve the algorithm Currying step by step in the Phix programming language
You may also check:How to resolve the algorithm Averages/Mode step by step in the C++ programming language
You may also check:How to resolve the algorithm Hostname step by step in the AppleScript programming language