AstrologySort


3 min read

Some days ago I was bored and searched the internet for something to do. Something productive. Naturally, I went straight to the okayest subreddit I know (/r/shittyprogramming) and searched for “idea” to get the hottest news on what one might productively do. And you will never guess what I’ve found… *clickbaiting intensifies*

Well, maybe you’ve guessed it with the help of the big fat title above this post: someone suggested to use astrology for sorting:

While i liked the idea of using a long proven “alternative source of truth” (as I like to call it) for sorting, I didn’t quite understand the predictions of this user concerning the runtime.

So I dusted off my vim and got to work.

Some Research

While thinking about how to realize an AstrologySort-algorithm, my first doubts in this project arose: What is astrology? How could it ever be used to sort a list of numbers? How do I exit vim?

So, after I killed my terminal, I reflected on my scientific education and went straight to the most trustworthy source I know: Google. The complicated and precisely targeted search term “Astrology” revealed all the information needed: astrology.com.

A screenshot of astrology.com

Almost instantly I spotted the “Numerology”-section of the website. I simply knew that this was the missing key to all my questions (except the one about how to exit vim).

But something still didn’t feel quite right. Not scientific enough. What I needed was hard evidence, the kind that could be cited in papers and stuff. So I looked up “Numerology” in Wikipedia. And there it was: A whole Wikipedia entry on this exact topic.

It has its own Wikipedia entry, therefore it must be real.

With this, I was ready to end the research intensive part of this project.

The Divine Source of Numbers

The most well known tool of applied Numerology is of course the “Daily Karmic Number”. I don’t exactly know how it works, but I guess it has something to do with karma (so it’s basically just like reddit). Every person has one Daily Karmic Number (DKN) for each day, but when I disabled cookies I got a new karmic number every time I loaded the page. Maybe I just have bad karma or something, but I went with it.

Daily Karmic Number on astrology.com

So I postulate that if a number is your DKN it is better for you and it should therefore be at the front of a sorted list. Likewise, when comparing two numbers, it should be clear that the number that appears first as a DKN should be before the other.

the_list = [4, 6, 3, 8, 9, 11, 3, 1]
sorted_list = []

while the_list:
    dkn = get_dkn()
    if dkn in the_list:
        sorted_list.append(dkn)
        the_list.remove(dkn)

In the code example above, the get_dkn-function connects to astrology.com and fetches the latest DKN.

When I tested my code I got some very unusual and unexpected results: the numbers in the list weren’t sorted. At least not by the definition I learned in algorithms 101.

Sorted list: [9, 11, 3, 8, 1, 6, 3, 4]

Turns out, the problem was not my implementation of the algorithm, but my expectations of it. The AstrologySort does not sort lists in a regular old-fashioned way. It sorts the numbers by personal karmic ability, which is much better than all the other sorting algorithms there are!

The Performance Test

But the word of that one redditor still remained in my head: “It might even be slower than BogoSort.”

That’s why I ran some simple performance tests with BogoSort and AstrologySort. I tested with random-numbered (1 <= x <= 9) list that ranged in size from 1 to 10. I checked for the number of iterations it took and for the time.

And as it turns out, the redditor was right! The chart shows clearly that while bogus sort is extremely fast for small lists, it is gets exponentially worse with larger lists. On the other hand, astrology sort is very slow for small lists and for large lists.

The same with the number of steps to complete the sorting. While bogus sort shows its exponential behavior, astrology sort is more or less constant in the amount of steps it takes (if you look at it from far enough - and that’s what astrology is all about).

So I just presented a constant time sorting algorithm, that sorts in such a special way that the numbers aren’t even ordered afterwards! A miracle? No. It’s just the way astrology works.