This blog no longer exists.
You will be redirected to something cool.

Saturday, October 20, 2012

My Sorting Algorithm: Melsort

A friend challenged me to a little algorithm writing contest and I'd never written an algorithm before (this was about a year and a half ago) and had little knowledge of algorithms.

Specs:
Write code that sorts an array of numbers from lowest to highest.
Use this array: [5, 2, 8, 0, 9, 3, 1]
Don't look up sorting algorithms.

It goes without saying that I was not allowed to Ruby's built-in sort method on the array => array.sort!
That would be cheating as the point is to create the code that sorts the array.

I thought of a number of ways to do this (I had a bubble sort-like piece of code that I never finished), but the quickest code I whipped up was this:


If the code is a bit hard to read, it does this:
I have two arrays. The original array containing unsorted numbers and an empty array where the sorted numbers will go.

Starting from zero, I count up one number at a time, checking each time if the number I just counted is in my unsorted array. If it does appear in the unsorted array, I add that number to the empty array. I stop counting when both arrays area equal (contain the same elements.)


There are two major problems with this:
1.) The code is unable to sort numbers with decimals.
2.) The code would be incredibly slow if the unsorted numbers were larger. For example, if the array contained 15 and the next highest number was 1587932057693576, the algorithm would count all the numbers in between 15 and 1587932057693576 before it could tell that 1587932057693576 was the next item to appear in the sorted array.

I won the contest as my sorting algorithm sorted the array faster than my friend's code did. However, considering the above problems, his code was far superior.

Spatial Skills on Facebook?

I recently took one of those Facebook feed reader quizzes where you let something read through your Facebook posts and it gives you some scores -- basically what kind of person you supposedly are. This isn't something I usually do, but I wanted to kind of play around with it and maybe come up with an analysis (and I did and it is as follows):

"Melanie is more spatial than 97% of people."

I can't agree with this. First of all, what does it mean to "be spatial"? Am I physically larger than 97% of people? Do I take up more space? Despite the ambiguity in the statement, I believe I know the intention: spatial reasoning skills.

I don't think there is a good way to determine, through my posts on social networks, what my spatial skills are.

I'll take the compliment, I suppose. I DO, in fact have a fairly 
high (in comparison to the general population:high; in comparison to a "genius": I'm an idiot, to be sure) visual-spatial ability, which is especially interesting given my gender (there was a study(1) that whose results showed that the more sexist a society is (toward women), the lower that females of said society score in a visual-spatial ability area of a cognitive test and that there is no known society where women regularly score higher than men. With this in mind, I highly doubt that I score higher than 97% of the population.(2.)

But, you do have to consider that this is a "facebook feed" test and that it's very possible that its results are wildly inaccurate. With this consideration in mind, you'd have to wonder why the test gives a spatial result. This result alone brings possible inaccuracies to the forefront given the formal nature of accurate(2) psychological testing.

1: I only know this because I dated a really sexist guy a bit back who provided this research as "proof" that men were somehow better than women. I took the research as proof that he was a dick. The study actually was fascinating, though.

2: There are some problems with this.
a.) It's likely they only compare you to people who have also taken the test. It was a Facebook app and as most apps go, they're a distant relative of glitter graphics. I was bored and decided to temporarily give my Facebook profile rabies so I could see what results this "test" gave me. Am I BETTER than everyone who installs an app? No, I install apps. Am I better than glitter graphics lovers. Probably. I'd need some empirical data to prove it, though, which definitely won't happen.
b.) Who says my posts are my own? I often share interesting things I find or maybe I'll post an interesting quote. In addition to this, my tweets are also posted to my Facebook feed and I often manually retweet things (copy and paste vs hitting the retweet button) which will cause it to show up on my feed.