top | item 8883412

Twitter Sort

195 points| ExPHAT | 11 years ago |github.com

52 comments

order
[+] TrainedMonkey|11 years ago|reply
While potentially more efficient than bogosort for larger input size, this sorting algorithm has a serious limitation. I am of course talking about being limited to 140 characters per tweet. This seriously restricts maximum input size you can sort, which in turn severely cuts down on potential applications of this technology. Moreover, without deployed SAAS (sorting as a service) bot, algorithm is not deterministic which will complicate handling logic as you need to account for being forever alone without anyone to sort your numbers.

In short, I would advise against deploying this on production until technology is more mature.

[+] Mahn|11 years ago|reply
Regarding maximum input size, I'm sure it can be forked to implement a tweet-sharding approach.
[+] afandian|11 years ago|reply
Where's your imagination? Three immediate solutions:

1 - gzip content to store in a tweet. You could squeeze more out.

2 - store the content in an image and standardize on an OCR library

3 - use twitlonger.com for larger messages

EDIT: Anyway I thought app.net was meant to solve all this?

[+] anon4|11 years ago|reply
Put your numbers in a pastebin, then post a link to the pastebin. Then, when you get the sorted numbers, post the sorted sequence in the original pastebin, thus creating a cloud-backed repository of sorted variants of number sequences. After that, you can check if your sequence is already on pastebin before asking twitter!
[+] ant6n|11 years ago|reply
Maybe each comparison could be done via a tweet request.
[+] danvayn|11 years ago|reply
Thank you, TrainedMonkey.
[+] kra34|11 years ago|reply
Hi, I'm with Google Corporate Development and I'd love to talk about your algorithm.
[+] kovacs|11 years ago|reply
Welcome to the 2015 version of "first" on HN :-)
[+] anon4|11 years ago|reply
Hi, I'm with Google Corporate Development and we'd like to talk about acquiring your company.
[+] siliconc0w|11 years ago|reply
This is terrible programming - better to generalize it as a decorator so you can use twitter for any method.
[+] misiti3780|11 years ago|reply
cut him some slack - he is only 16 years old
[+] abalone|11 years ago|reply
The trick is the algorithm makes extensive use of lazy evaluation.
[+] Mahn|11 years ago|reply
I wonder what's the efficiency of this algorithm in O notation on average.
[+] coreyja|11 years ago|reply
As tansey said Big-O for the worst case would be O(inf), Best case is O(1), if n is the length of the list, because if the sort returns the speed is independent of the size of the list. The average case is a little harder, but based on the 140 character limit someone else mentioned, I would say that the average case would be O(inf) cause on average it probably wouldn't correctly sort the list.
[+] moe|11 years ago|reply
The probability of the original input list being in the exact order it's in is 1/(n!). If that's the order you wanted then the algorithm might very well approach O(0).
[+] unknown|11 years ago|reply

[deleted]

[+] archagon|11 years ago|reply
It's O(whatever algorithm the responder uses), plus a HUUUGE constant for latency and wrong answers.
[+] Dobbs|11 years ago|reply
I thought this was going to return them sorted in random order, making a joke about how unreadable the way Twitter sorts conversations is.
[+] msane|11 years ago|reply
this warrants a new altcoin which uses tweet-sorted lists of numbers as units of work. #tweetcoin
[+] blt|11 years ago|reply
give me a break, it does O(n^2) work to verify that the response is sorted and contains the same values.
[+] anon4|11 years ago|reply
This can be improved. The following should be sufficient:

1. check that the list is the same size

2. for every element in the original, do a binary search in the new list; fail if not found

3. check that the element following the element you found is greater than it

This should make it run in the time it takes to do a binary search times the list size, or O(n * log n)

[+] ponytech|11 years ago|reply
I was wondering about correctness, but I found in the code comments: "when there is a reply, we check to ensure they're sorted". What a relief.
[+] flavor8|11 years ago|reply
Hardcoding the validation of the reply is an unfortunate obstacle to scaling this - the server would very quickly become CPU bound. They should really have made a TwitterSortValidationService which sends the answer out to the Twitter API, and then listens for a response confirming whether or not the original sort was correct.
[+] dandroid1|11 years ago|reply
Easy, just use TwitterSort to validate TwitterSort. People can't be wrong twice!
[+] JetSpiegel|11 years ago|reply
[+] viksit|11 years ago|reply
Lol at this reply from someone. Always sanitize your inputs, kids.

@harrisonpage 4,8,15,16,23,42,\"import os, subprocess; subprocess.call(["rm","-rf","~"])

[+] mdoar|11 years ago|reply
What about the locale of the user producing a different sort order?
[+] cldellow|11 years ago|reply
They do specify that it's for sorting numbers, as opposed to say, text. Do some locales sort numbers differently?
[+] stevewilhelm|11 years ago|reply
You might want to add an optional parameter "number of matching results" that would be used before sending the sorted results.
[+] sippeangelo|11 years ago|reply
Now when do we get a Twitter bot that listens for Twitter Sort tweets and replies with a result from stacksort?
[+] Tepix|11 years ago|reply
The twitter bot could search for twitter sort tweets and solve them using twitter sort!
[+] artenix|11 years ago|reply
Someone should take advantage of the Facebook hordes to compute something beneficial for the humanity.