Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

Genius sorting algorithm: Sleep sort

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

Name: Anonymous 2011-06-16 3:54

>>200
are you calling coldfusion a toy lang? you clearly havent done enterprise development

Name: Anonymous 2011-06-16 4:00

>>200
so sick,mother fucker

Name: Anonymous 2011-06-16 4:06

sb sb

Name: Anonymous 2011-06-16 4:08

>>200
sb sb

Name: Anonymous 2011-06-16 4:19

fu

Name: Anonymous 2011-06-16 4:37

Who the fuck posted this to Reddit? God damn it.

Name: Anonymous 2011-06-16 4:40

import Control.Concurrent;

sleepsort = mapM_ $ forkIO . (\i -> threadDelay (i * 1000000) >> print i)

main = do
    sleepsort [1, 5, 3, 7, 8, 5, 3, 2, 6, 1, 6]
    threadDelay 10000000

Name: Anonymous 2011-06-16 4:54

I heartily disagree with all the attempts to downplay the brilliance of the sleep sort algorithm. Many of you have missed the important point that while traditional sorting algorithms can only utilize one core, sleep sort has the capacity to use the full power of a massively parallel execution environment.

Given that you need nearly no computing in each of the threads, you can implement them using low-power CPUs, so this is in fact a GREEN COMPUTING algorithm.

Oh, and did I mention that the algorithm can also run inside a cloud...?

Sure, you're a genius!

Name: Anonymous 2011-06-16 4:55

Isn't this something GPGPUs are made for?

Name: Anonymous 2011-06-16 4:57

How about adding the n time that is needed to iterate through all elements and then cut sleep time like $1/1000, it will complete with 1000 times faster ??

Name: Anonymous 2011-06-16 5:00

>>210
it is still linear so does not matter

Name: Anonymous 2011-06-16 5:17

Code on 4chan??

Where is the lolcats?? :D

Name: Once 2011-06-16 5:24

n input num map to [0,x], cost O(n)
get niubility cpu support usleep(time) with min time=x/n (second)
the algorithm is O(n)+x second

Name: Anonymous 2011-06-16 5:37

This was such a good thread, it's ruined now ;_;

Name: Anony-mouse 2011-06-16 5:37

Now I'm waiting for some *fag-sort* to get discovered. See simple and time saver. ;)

Name: Anonymous 2011-06-16 5:39

<>

Name: Anonymous 2011-06-16 5:43

>>214
`>implying every thread on /prog/ isn't ruined from the start by design

Name: Anonymous 2011-06-16 5:47

>>217
I'd rather have the thread die because of ``autism'' spam than because of the people from reddit.

Name: AK 2011-06-16 5:57

you guys suck

Name: Anonymous 2011-06-16 6:31

>>201 you clearly don't get it, do you?

Name: Anonymous 2011-06-16 6:47

//golang

package main

import (
    "fmt"
    "time"
)

func main() {
    tab := []int{1, 3, 0, 5}

    ch := make(chan int)
    for _, value := range tab {
        go func(val int){
            time.Sleep( int64(val)*10000000 )
            fmt.Println(val)
            ch <-val
        }(value)
    }

    for _ = range tab {
         <-ch
    }
}

Name: Anonymous 2011-06-16 6:54

check my trebs ^__^

Name: Anonymous 2011-06-16 6:55

>>221
Go
``Please" don't.

Name: Anonymous 2011-06-16 6:58

Who are all the faggot retards who are taking this shit seriously?

RETARD THREAD IS RETARD

Name: Anonymous 2011-06-16 7:17


                                                
                        _,-%/%|                 
                    _,-'    \//%\               
                _,-'        \%/|%               
              / / )    __,--  /%\               
              \__/_,-'%(%  ;  %)%               
                      %\%,   %\                 
                        '--%'                   
                                                
                                                 .

                                                
                        _,-%/%|                 
                    _,-'    \//%\               
                _,-'        \%/|%               
              / / )    __,--  /%\               
              \__/_,-'%(%  ;  %)%               
                      %\%,   %\                 
                        '--%'                   
                                                
                                                 .

                                                
                        _,-%/%|                 
                    _,-'    \//%\               
                _,-'        \%/|%               
              / / )    __,--  /%\               
              \__/_,-'%(%  ;  %)%               
                      %\%,   %\                 
                        '--%'                   
                                                
                                                 .

                                                
                        _,-%/%|                 
                    _,-'    \//%\               
                _,-'        \%/|%               
              / / )    __,--  /%\               
              \__/_,-'%(%  ;  %)%               
                      %\%,   %\                 
                        '--%'                   
                                                
                                                 .

                                                
                        _,-%/%|                 
                    _,-'    \//%\               
                _,-'        \%/|%               
              / / )    __,--  /%\               
              \__/_,-'%(%  ;  %)%               
                      %\%,   %\                 
                        '--%'                   
                                                
                                                 .

                                                
                        _,-%/%|                 
                    _,-'    \//%\               
                _,-'        \%/|%               
              / / )    __,--  /%\               
              \__/_,-'%(%  ;  %)%               
                      %\%,   %\                 
                        '--%'                   
                                                
                                                 .

                                                
                        _,-%/%|                 
                    _,-'    \//%\               
                _,-'        \%/|%               
              / / )    __,--  /%\               
              \__/_,-'%(%  ;  %)%               
                      %\%,   %\                 
                        '--%'                   
                                                
                                                 .

                                                
                        _,-%/%|                 
                    _,-'    \//%\               
                _,-'        \%/|%               
              / / )    __,--  /%\               
              \__/_,-'%(%  ;  %)%               
                      %\%,   %\                 
                        '--%'                   
                                                
                                                 .

                                                
                        _,-%/%|                 
                    _,-'    \//%\               
                _,-'        \%/|%               
              / / )    __,--  /%\               
              \__/_,-'%(%  ;  %)%               
                      %\%,   %\                 
                        '--%'                   
                                                
                                                 .

                                                
                        _,-%/%|                 
                    _,-'    \//%\               
                _,-'        \%/|%               
              / / )    __,--  /%\               
              \__/_,-'%(%  ;  %)%               
                      %\%,   %\                 
                        '--%'                   
                                                
                                                 .

                                                
                        _,-%/%|                 
                    _,-'    \//%\               
                _,-'        \%/|%               
              / / )    __,--  /%\               
              \__/_,-'%(%  ;  %)%               
                      %\%,   %\                 
                        '--%'                   
                                                
                                                 .

                                                
                        _,-%/%|                 
                    _,-'    \//%\               
                _,-'        \%/|%               
              / / )    __,--  /%\               
              \__/_,-'%(%  ;  %)%               
                      %\%,   %\                 
                        '--%'                   
                                                
                                                 .

                                                
                        _,-%/%|                 
                    _,-'    \//%\               
                _,-'        \%/|%               
              / / )    __,--  /%\               
              \__/_,-'%(%  ;  %)%               
                      %\%,   %\                 
                        '--%'                   
                                                
                                                 .

                                                
                        _,-%/%|                 
                    _,-'    \//%\               
                _,-'        \%/|%               
              / / )    __,--  /%\               
              \__/_,-'%(%  ;  %)%               
                      %\%,   %\                 
                        '--%'                   
                                                
                                                 .

                                                
                        _,-%/%|                 
                    _,-'    \//%\               
                _,-'        \%/|%               
              / / )    __,--  /%\               
              \__/_,-'%(%  ;  %)%               
                      %\%,   %\                 
                        '--%'                   
                                                
                                                 .

Name: Anonymous 2011-06-16 7:27

ITT: niggers and black people

Name: sigs 2011-06-16 7:39

>>180

Parse error: missing the matching [

Name: Anonymous 2011-06-16 7:43

>>227
are you actually that stupid?

Name: Anonymous 2011-06-16 7:48

./sleepsort.sh `seq -s' ' 1 1500` 1
1
2
3
4
5
6
7
8
9
1 // <--- Ooooops
10
11
12

Name: Anonymous 2011-06-16 7:55

$ ./sleepsort.sh 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
./sleepsort.sh: fork: Resource temporarily unavailable
./sleepsort.sh: fork: Resource temporarily unavailable
./sleepsort.sh: fork: Resource temporarily unavailable
./sleepsort.sh: fork: Resource temporarily unavailable
$ 1 <- yup it returned to shell here
1
1
1
1
1
1
1
1
1
1
1
1                
1
1
1
1
1
1
1

Name: Anonymous 2011-06-16 8:01

oh shii

Name: Xeni Jardin 2011-06-16 8:50

Kudos guise!!! I don't quite understand the details of this program, but I like the name. Will blog it. DESUDESUDESU Oh and I can't believe I'm on 4chan for 2 whole years and never heard of text boards before! PUDDI PUDDI!

Name: Aijoona 2011-06-16 8:51

// Javascript

function lazySort(list, callback) {
    var result = [];

    list.forEach(function(i) {
        setTimeout(function() {
            result.push(i);
           
            if(result.length == list.length) {
                callback(result);
            }
        }, i);
    });
}

lazySort([4,5,7,1,2,4,5], alert);

Name: Anonymous 2011-06-16 9:07

Great, now Randall is going to make a shitty comic about this.

Name: Anonymous 2011-06-16 9:12

RIP Sleepsort thread.
2011/01/20 - 2011/06/16

Name: Anonymous 2011-06-16 9:18

Name: Anonymous 2011-06-16 9:18

>>234
I hope he does. I find his comics hilarious.

Name: Anonymous 2011-06-16 9:19

<--check'em dubs

Name: Anonymous 2011-06-16 9:20

>>236
Incidentally, what makes this algorithm really interesting is that there actually exist real-life applications. For instance, DNA sequencing (Sanger sequencing) depends on something like this to sort DNA fragments according to their length (and more generally, every electrophoresis does something similar). The difference is that sequencing is performed physically, not in a computer.

It's biotechnology!

Name: Anonymous 2011-06-16 9:22

>>236
Great, and soon a wikipedia page...

Newer Posts