Ineffective Sorts

Post about your cool new gadgets and toys. Ask other users for help with techy problems.

Ineffective Sorts

Postby MM_Dandy » Wed Mar 13, 2013 10:12 pm

XKCD for 13 March:

Ineffective Sorts

This is funny enough, but when I read it, I immediately thought "And then there's me - I'm an ineffective sort."
User avatar
MM_Dandy
Moderator
Moderator
King of Obscurity
 
Posts: 4927
Joined: Thu May 12, 2005 9:02 pm
Location: Canton, SD, USA

Re: Ineffective Sorts

Postby Мастер » Sun Mar 31, 2013 7:29 am

What language are these written in?

The first one looks very ineffective, if I'm analysing it correctly, it looks like it will never sort anything, and go into an infinite recursion if the length of the list is more than one.

ETA - that's if I'm understanding the syntax of the lines which assign values to A and B correctly. Under a different possible interpretation (again, I don't know what language this is), it looks like it returns the original list.
They call me Mr Celsius!
User avatar
Мастер
Moderator
Moderator
Злой Мудак
Mauerspecht
 
Posts: 23943
Joined: Tue Aug 02, 2005 2:56 pm
Location: Far from Damascus

Re: Ineffective Sorts

Postby Lance » Sun Mar 31, 2013 2:25 pm

Yeah, I think it returns the original list and apologizes.
No trees were killed in the posting of this message.
However, a large number of electrons were terribly inconvenienced.

==========================================

Build a man a fire and he will be warm for a few hours.
Set a man on fire and he will be warm for the rest of his life.
User avatar
Lance
Administrator
Administrator
Cheeseburger Swilling Lard-Ass who needs to put down the remote and get off the couch.
 
Posts: 91437
Joined: Thu May 12, 2005 5:51 pm
Location: Oswego, IL

Re: Ineffective Sorts

Postby Мастер » Sun Mar 31, 2013 2:47 pm

OK, then in whatever language this is, one of the assignments to A or B must include the pivot, and the other must not.

Some of the others look like they will work sometimes :P
They call me Mr Celsius!
User avatar
Мастер
Moderator
Moderator
Злой Мудак
Mauerspecht
 
Posts: 23943
Joined: Tue Aug 02, 2005 2:56 pm
Location: Far from Damascus

Re: Ineffective Sorts

Postby MM_Dandy » Mon Apr 01, 2013 7:30 pm

I think it's python, more or less. The bottom left is pseudo code.

Assuming that it's python, and that I've read the documentation for slices correctly, the assignment to A does not get the pivot, while the assignment to B does. So, the first time through, given a list of length 35, we have:

Code: Select all
// Passing in a list containing elements 0 - 16 of LIST (LEN == 17)
A = HALFHEARTEDMERGESORT(LIST[:17])
// Elements 17-34 of LIST (LEN == 18)
B = HALFHEARTEDMERGESORT(LIST[17:])
User avatar
MM_Dandy
Moderator
Moderator
King of Obscurity
 
Posts: 4927
Joined: Thu May 12, 2005 9:02 pm
Location: Canton, SD, USA


Return to Computers and Gadgets

Who is online

Users browsing this forum: No registered users and 1 guest