
Twitter Sort - ExPHAT
http://github.com/ExPHAT/twitter-sort
======
TrainedMonkey
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
Regarding maximum input size, I'm sure it can be forked to implement a tweet-
sharding approach.

~~~
wging
Merging of tweet shards is also possible via the same mechanism. Just
tweeterate through the retrieved shards and merge them one by one. To merge
two lists, compare elements pairwise. To compare elements pairwise, construct
a two element list and sort this list via the short-form tweetsort api.

~~~
emmanueloga_
For sorting big lists of numbers mergesort could be used, only resorting to
twittersort when the list of numbers is small enough [1]. In fact, that's the
way mergesort is generally implemented (except the "cutoff" algorithm is
usually insertionsort, not tweetsort :p).

1:
[http://en.wikipedia.org/wiki/Merge_sort#Optimizing_merge_sor...](http://en.wikipedia.org/wiki/Merge_sort#Optimizing_merge_sort)

------
kra34
Hi, I'm with Google Corporate Development and I'd love to talk about your
algorithm.

~~~
kovacs
Welcome to the 2015 version of "first" on HN :-)

------
gkoberger
If that turns out to be a bit slow, there's always StackSort:

[http://gkoberger.github.io/stacksort](http://gkoberger.github.io/stacksort)

------
siliconc0w
This is terrible programming - better to generalize it as a decorator so you
can use twitter for any method.

~~~
misiti3780
cut him some slack - he is only 16 years old

------
jpatokal
This is almost, but not quite, as cool as the WikiClock.

[http://pageoftext.com/wikiclock](http://pageoftext.com/wikiclock)

------
stonewhite
I do believe this may have a worse average case performance than sleepsort.

[https://dis.4chan.org/read/prog/1295544154](https://dis.4chan.org/read/prog/1295544154)

------
abalone
The trick is the algorithm makes extensive use of lazy evaluation.

------
Mahn
I wonder what's the efficiency of this algorithm in O notation on average.

~~~
coreyja
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.

~~~
pliny
The speed is definitely not independent of the size since you still have to
write a string of size O(n).

------
Dobbs
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
this warrants a new altcoin which uses tweet-sorted lists of numbers as units
of work. #tweetcoin

------
blt
give me a break, it does O(n^2) work to verify that the response is sorted and
contains the same values.

~~~
anon4
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)

------
askmike
Instead of sorting to verify[1] the tweet has indeed been correctly sorted it
might be better to just check the first and last entry. As the dataset might
be very large (the current 140 character imposted by Twitter limit is merely
an implementation detail).

[1] [https://github.com/ExPHAT/twitter-
sort/blob/master/main.py#L...](https://github.com/ExPHAT/twitter-
sort/blob/master/main.py#L67-L81)

------
ponytech
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
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
Easy, just use TwitterSort to validate TwitterSort. People can't be wrong
twice!

~~~
garyhost
Even better, use stacksort to validate twitter sort! That means you get
redundant architecture!

------
JetSpiegel
[https://duckduckgo.com/?q=!twitter+Those+numbers+aren%27t+so...](https://duckduckgo.com/?q=!twitter+Those+numbers+aren%27t+sorted)

Still no uses of this in the wild.

~~~
viksit
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
What about the locale of the user producing a different sort order?

~~~
cldellow
They do specify that it's for sorting numbers, as opposed to say, text. Do
some locales sort numbers differently?

~~~
nacs
They could interpret the input data differently.

For example, a decimal mark difference[1] between locales (like comma instead
of a period in floating point numbers) could yield bad results.

[1]
[https://en.wikipedia.org/wiki/Decimal_mark](https://en.wikipedia.org/wiki/Decimal_mark)

------
kctess5
[https://github.com/kctess5/twitter-sort-
response](https://github.com/kctess5/twitter-sort-response)

------
stevewilhelm
You might want to add an optional parameter "number of matching results" that
would be used before sending the sorted results.

------
sippeangelo
Now when do we get a Twitter bot that listens for Twitter Sort tweets and
replies with a result from stacksort?

~~~
Tepix
The twitter bot could search for twitter sort tweets and solve them using
twitter sort!

------
artenix
Someone should take advantage of the Facebook hordes to compute something
beneficial for the humanity.

------
yitchelle
Cant wait to see other derivatives Facebook sort or Linkedin sort....

