User Tag List

Results 1 to 4 of 4

  1. #1
    Senior Member man's Avatar
    Join Date
    Sep 2009
    MBTI
    IntP
    Enneagram
    =)
    Socionics
    =)
    Posts
    331

    Red face my new sorting algorithm - mansort

    Code:
    import random
     
    def mansort(x):
        while not sorted?(x):
            random.shuffle(x)
        return x
     
    def sorted?(x):
        if not x:
            return True
        last = x[0]
        for y in x[1:]:
            if y < last:
                return False
            last = y
        return True
    constructive criticism appreciated
    [SIGPIC][/SIGPIC]

  2. #2

    Default

    Quote Originally Posted by man View Post
    Code:
    import random
     
    def mansort(x):
        while not sorted?(x):
            random.shuffle(x)
        return x
     
    def sorted?(x):
        if not x:
            return True
        last = x[0]
        for y in x[1:]:
            if y < last:
                return False
            last = y
        return True
    constructive criticism appreciated
    It is a wonderfully whimsical sorting algorithm: there is no guarantee of termination...and the probability of termination is somewhere around ~1/n! Awesome. The average bound for the time complexity of this sort is factorial time or rather O(n*n!) because the "sorted?" function is linear time (and I am assuming python's shuffle is also linear time).

    This is even more whimsical than the "lets try every permutation, till we find the sorted one", because this brute force algorithm guarantees termination, and can only get a worst-case time complexity to match your average.

    Well done! I wish I was in the mood to write a perl poem describing it, but I am not.

    EDIT: One failing, however, is that when it does terminate, it terminates with the correct output...but I suppose removing that would change it from an act of whimsy to just plain wrong.

    Accept the past. Live for the present. Look forward to the future.
    Robot Fusion
    "As our island of knowledge grows, so does the shore of our ignorance." John Wheeler
    "[A] scientist looking at nonscientific problems is just as dumb as the next guy." Richard Feynman
    "[P]etabytes of [] data is not the same thing as understanding emergent mechanisms and structures." Jim Crutchfield

  3. #3
    Senior Member man's Avatar
    Join Date
    Sep 2009
    MBTI
    IntP
    Enneagram
    =)
    Socionics
    =)
    Posts
    331

    Default

    Quote Originally Posted by ygolo View Post
    EDIT: One failing, however, is that when it does terminate, it terminates with the correct output...but I suppose removing that would change it from an act of whimsy to just plain wrong.
    Listen up brah, this isn't just code -- it's a revolution.

    Why would I implement a sorting algorithm that doesn't return the correct output???
    [SIGPIC][/SIGPIC]

  4. #4
    garbage
    Guest

    Default

    It's genius. It's like.. it's like it embraces the perpetual chaos of the world and locks in on the absolute perfect moment in time, where the stars just happen to align and everything just 'clicks.'

    Although, it does already exist. But at least you've reaffirmed genius.

Similar Threads

  1. my new Rims xD
    By entropie in forum Science, Technology, and Future Tech
    Replies: 4
    Last Post: 05-30-2008, 02:21 AM
  2. My New Filing Technique is UN-STOPPABLE!
    By CzeCze in forum Arts & Entertainment
    Replies: 9
    Last Post: 03-15-2008, 02:05 AM
  3. Let's discuss my new favorite game...
    By The Ü™ in forum Arts & Entertainment
    Replies: 9
    Last Post: 11-23-2007, 08:41 PM
  4. Show my new Kitty some love
    By Sahara in forum The Fluff Zone
    Replies: 54
    Last Post: 07-31-2007, 07:25 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
Single Sign On provided by vBSSO