Saturday, November 1, 2014

Big Hero Six Prediction

Spoilers?: None. The movie isn't out yet. This is all theory based on the first and second trailer. But it includes information from my rant "Frozen Hans" so you'll need to finish watching the movie Frozen by indirect spoilers.

Rant warning: this is a rant. Read accordingly. So don't accuse me of hating everything and being overly analytical.

I only saw the second trailer: https://www.youtube.com/watch?v=8IdMPpKMdcc. I haven't seen commercials or anything else about it.

Why does it start with death? (Tadashi is dead as per "isn't gone as long as we remember him" which is a common thing to say when dealing with death.) You just did that in Up then Frozen we don't need it again (especially not twice in a row). He doesn't even need to die. The conversation could go like this. Them: "oh no a super villain! We need you to build a battle robot" Tadashi: "well Baymax took years so I'll need at least a few months" Them: "we don't have that much time". And done now he can't make the plot trivial and you still have to weaponize Baymax.

Seriously a kabuki mask? You might as well be wearing a t-shirt that says "I'm not someone you know". Why else would he be hiding his face? Villains love to brag but the movie hides his face from us? This obviously means something, I can smell a twist. And here it is: he's Tadashi. They have about the same body and who else could it be? Obvious plot twist which is the exact same twist done in Frozen (good guy turns out to be bad). Seriously? A second thing copied from Frozen. Look I know Frozen was a great movie but get over it Disney and be creative. Anyway if he wasn't someone we/ the characters would know then it doesn't make sense to hide his face. At the end of the movie they'd be like "now let's take off this mask and see who it is... IT'S! Some guy we don't know?... Ok whatever." that would be a waste and be weird, Disney wouldn't do that.

Motivation you say? Here it is. Tadashi: "great inventions come from time of need. I build Baymax to make sure you wouldn't die. I just wanted you [his brother] to do great things." done. The entire plot writes itself from here.

Ok I just saw the first trailer (https://www.youtube.com/watch?v=z3biFxZIJOQ). Kabuki mask uses microbots. Strong evidence that it is Tadashi. Also notice how in a scene microbots are about to attack (the one where Baymax says "I am not fast") but then basically waits for them to escape. The microbots are just sitting there being a wall for a few seconds while you guys get a head start. Yeah right.

So what do you want from us Disney? We can't trust white washed tombs and now we can't trust dead people? What's next: we can't trust anyone who isn't Disney? This is a preemptive rant and I hope I don't need a follow up rant after I've seen the movie (but we'll see about that).

Don't get me wrong. I want to see the movie and it looks good. I hope I'm wrong and they they actually put effort into the plot. But this is Disney we're talking about after all. They copied plots from lots of things early on but recently got creative, it's hard to say if they were lazy with the main motivation or not.

Also I just noticed this: the girl that says "a lunatic in a mask just tried to kill us" looks angry. But she doesn't sound very angry and why is she stating the obvious? Well for the trailer but besides that I suspect that she's in on Tadashi's plot as a "man on the inside" to make sure his brother is inventing stuff as planned and making sure the heroes don't get stuck or hopeless etc.

Frozen Hans

No not "frozen hands" I am referring to the character Prince Hans Westerguard of the Southern Isles from the Disney movie Frozen.

Spoilers!: You need to have finished the movie Frozen.

Rant warning: this is a rant. Read accordingly. So don't accuse me of hating everything and being overly analytical.

Ok many people saw his betrayal coming but how? What evidence does the movie give, ie what foreshadowing is there? And how could we have guessed that?

No apparent villain. Ignoring Hans there was no apparent villain and you would expect a Disney movie to have a villain of some kind. There was The Duke of Weselton. The Duke was in fact a villain but couldn't be taken seriously. He was designed unlikable, bland, and ugly. Disney has a history of great villains and villain songs. Especially recently were the villains have gotten even better. So to see this guy as an obvious step down.. Well let's just say "it's a trap!".

Expect a plot twist. If you looked at the time when Anna got back home there was still room for plenty of movie and there hasn't been a plot twist yet so it seemed like an obvious place to put one. But personally I was expecting Hans to kiss her, nothing would happen, and they'd have to go find Kristoff but the Duke would interfere (to pad the movie despite being unrelated to money which is his only motivation).

Elsa implies they won't be together. She said something like "You can't marry a man you just met". You can't marry a villain but you can marry an ally. This was a weird statement coming from Disney though, have they changed their ways? Are they treating marriage more seriously now, actually requiring a deep relationship? Apparently not since the trolls try to force marry Anna and Kristoff despite only being together for a couple of days. But on the other hand that was a joke and foreshadowing.

Hans's wants to be king. He says he's not in line for his kingdom's throne because he has 12 brothers and sisters. But then he said "the only way for me to see the throne is to marry into it" followed by saying that Elsa was ideal but no one was getting anywhere with her. This indicates that he wants to have a throne which is further supported by his hasty proposal to Anna.

Counter point: there was no signs of Hans being evil. In fact he was nice and specifically told the guards not to kill Elsa even though everyone else wanted her dead. He was friendly, understanding, and cool headed. He openly talked to Anna about his back story and motivations which would appear to be honesty. He was also caring and considerate when he helped save the lives of the citizens at the expense of the kingdom. In fact when the Duke disapproved of spending wealth Hans responded by threatening the Duke showing that Hans is willing to stand up for what is right and defend the weak. Even though they weren't his people yet he was still treating them well even at the cost of his future wealth (which he didn't end up getting).

Disregard all supporting evidence. No apparent villain: The Duke was a villain albeit minor and there didn't actually need to be a villain at all, the whole plot could revolve around the misunderstanding, mistrust, lack of control, etc. If you change the ending so that Anna is saved by the kiss of Kristoff and Hans isn't a villain, then they could've gone to Elsa had a heart warming moment and the plot resolved. It still would've been a great movie even without a villain of any kind (even the Duke). Expect a plot twist: Like I said I was expecting Hans's kiss to fail and Kristoff's to work. Who didn't expect Anna to be healed by the kiss of Kristoff? Elsa implies they won't be together: this implies that the kiss of Hans can't heal Anna but doesn't mean that Hans is evil. For reference see the movie Maleficent and how sleeping beauty failed to wake up the first time (that was too obvious and vague I don't consider it a spoiler). Hans's wants to be king: there are plenty of people who want to be king that are not evil. For reference see many other Disney movies, specifically The Sword in the Stone.

Abraham Lincoln took scissors to the Bible cutting out all miracles and God. He, Hans, and the Pharisees were like white washed tombs: clean on the out side but full of death on the inside (Matthew 23:27). So what do you want from us Disney? You only showed us the outside (until the big twist) of Hans and never showed any indicators that death was inside. Do you want us to be paranoid and distrust even the nicest of people? And don't say "the moral of the story is that you need to get to know people more" BS! We knew more about Hans then we did about Kristoff, for all we know Kristoff is still planing his even more evil plan. No seriously think about this for a second, what do we really know about Kristoff's personality? He is friendly, jokes around by giving Anna a hard time, is more of a loner so he has trouble relating to people. And um... uh... Is that it? Potential off screen character depth that Anna would've learned doesn't count because I'm talking about the viewer's perspective. If I recall he assumed Elsa was hopeless and quickly told Anna to give up. He has more negative character traits than Hans! And we know far less about him. So then why does Disney have this twist? Are the immature enough that they wanted to say "haha you couldn't see the twist that I designed so that you couldn't see it" ignoring the ramifications? Kids watched this movie so they'll pick up on lessons to take away from it even if you don't want them to. And how immature that statement is, that's like laughing at people for not being able to see the invisible man. Of course no one can see him HE'S INVISIBLE! So they were an idiot, did something childish, and potentially corrupted the youth, thanks Disney.

So then how did people know that Hans was evil? They didn't. They guessed based on what they know about Disney. They knew that Disney always has a good villain (the Duke couldn't be taken seriously). They knew that there was going to be a big twist because Disney has been doing that recently and this seemed like the right kind of movie for it. They knew there was still plenty of time left in the movie and saw that the Duke was being a red herring. The Duke was obviously a red herring because Disney always has good villains and the Duke was designed as unlikable and ugly. Why would they include a red herring: there must be a twist villain.

The lack of foreshadowing for Hans was my biggest complaint about the movie Frozen. Fyi the other two are in order: the first song was a big lipped alligator moment which confused me about Kristoff. And the winter dissolved too quickly. I get that the plot is done but it kinda gave me whiplash, couldn't you make it take at least 10 minutes to dissolve? With a fast forward of course. But Frozen is still a great movie and I endorse it.

Thursday, October 30, 2014

Sorting Algorithms: Ascii, Alphabetical, and Title

It bugs me when I see people use the phrases "sort alphabetically" and "ascii sort" or "by character code" interchangeably, they are not the same thing. But instead of ranting about it I decided to define them. I will be assuming all sorts are ascending. The definition for Ascii is fairly well accepted and this is the simplest sort.

Sort by Character code


Input must only be strings of known length.

Compare the character codes of each character until they are different at which point the lower code number comes first. If one string starts with the other then the shorter string comes first. Note that this includes the null character.

Implementation problem: some programming languages use null terminated strings but this sorting algorithm allows null within the string therefore special care will be needed.

Note that the algorithm can correctly sort strings of any fixed width character encoded without needing to know how to read the characters. Variable width character encoding, on the other hand, would need to be interpreted to get the correct order. Because of the ability to handle other encodings beyond ascii it would more accurately be called character code sorting.

Here is a javascript implementation for it (javascript allows nulls in strings):
function characterCodeAscending(a,b)
{
   for (var i=0; i < a.length; i++)
   {
       if(i >= b.length) return 1;
       if(a.charAt(i) !== b.charAt(i)) return (a.charCodeAt(i) - b.charCodeAt(i));
   }
    if(b.length > a.length) return -1;
    return 0;
}
//that was for the sake of illustration. for brevity use this instead:
function compareTo(a,b)
{
    if(a === b) return 0;
    if(a > b) return 1;
    return -1;
}


Alphabetical sort algorithm definition.


Input must only be strings of known length. Strings can't contain non-printable characters (such as null). Case is ignored and the rest is the same as character code sorting. This definition is accepted as far as I know.

Since strings don't normally contain non-printable characters the similarity of definitions is why people sometimes confuse them. But the big difference between them is that Alphabetical is case insensitive. This means that "STRING VALUE" has the same order as "string value".

Note that null terminated strings don't need special handling for alphabetical. But encoding must always be known to determine upper and lower case.

javascript implementation (input is not validated for printable characters):
function alphabetical(a,b){return compareTo(a.toLowerCase(),b.toLowerCase());}  //see above for compareTo definition


Book Title sort algorithm definition.


It is used for books, movies, and other media. Input must only be strings of known length. Strings can't contain non-printable characters (such as null). The only whitespace allowed is a space. A space may not be next to another space. Trailing and leading spaces are not allowed. Start with the definition for alphabetical with some differences.

Punctuation is ignored, only alphabetical and numeric symbols are used when determining order. Eg, "Joe's?" is the same as "j!O,e...s". What is considered alphabetical is determined by the language (linguistic). Note that the number of alphanumeric characters must be counted to determine the effective string length.

Leading articles are ignored: "a", "an", and "the". If the string starts with one of these 3 articles (or equivalent if not using English) it will be ignored for name comparison. Only the first word will be ignored and only if it contains at least 2 words. Eg, "The the name" only ignores the first word but for "The" and "But I..." nothing is ignored. If 2 titles differ only by leading article then they should be sorted with the article included thus "The Wind" will come before "Wind".

Titles should be split by the first colon. The part before the colon is the series name and the part after is the subtitle. The subtitle is ignored unless the series name is the same. If a colon does not exist then the entire thing is considered the series name. The series name may end in a number in which case they should be sorted numerically ascending. For example "1999 Encyclopedia Volume 2" comes before "1999 Encyclopedia Volume 10" even though alphabetically 10 comes before 2. This should take into account any numbering system such as Roman numerals, numeric, and numbers as words. Humans can do their best to determine the numbering system but this is where computer implementation becomes impossible. If the series names are the same then the subtitle is compared alphabetically (not via title sort, eg do not ignore the word "the" etc). A series name that does not have a number should come first (ie be considered 1).

Example difficulties. There is a video game named "Final Fantasy X-2" (ten two) it is a sequel to ten but is not related to eleven, a human would sort them "Final Fantasy X", "Final Fantasy X-2", "Final Fantasy XI" (apparently FF11 has a box). But even if a computer recognized the Roman numeral numbering it would see "X-2" as unrelated text and place it before all of the ones in the number sequence (it would actually make more sense to have "-2" be the subtitle and therefore be placed after 10). These Metal Gear Solid games should be in this order:
Metal Gear
Metal Gear 2: Solid Snake
Metal Gear Rising: Revengeance
Metal Gear Solid
Metal Gear Solid: Peace Walker
Metal Gear Solid 2: Sons of Liberty
Metal Gear Solid 3: Snake Eater
Metal Gear Solid 4: Guns of the Patriots
Metal Gear Solid V: Ground Zeroes
Metal Gear Solid V: The Phantom Pain
A title without a numeric should be considered 1 (or rather negative infinity). Notice how it switches from numeric digits to Roman numerals and how there are 2 "Metal Gear Solid V"s (and 1s even though Peace Walker isn't actually).

Despite these programmatic difficulties the algorithm should not go to great lengths to account for everything. It is impossible to account for all possible scenarios therefore use a fairly simple algorithm and then manually rearrange the exceptions afterwards.

Here is a javascript implementation for Book Title sorting. It only uses non-extended ascii and is English.
function titleSort(titleA, titleB)
{
    var stripA = titleA.toLowerCase().replace(/[^a-z0-9 :]/g, '').trim().replace(/ +/g, ' ');
    var stripB = titleB.toLowerCase().replace(/[^a-z0-9 :]/g, '').trim().replace(/ +/g, ' ');

    if(stripA !== stripB && stripA.replace(/^(?:an?|the) /, '') === stripB.replace(/^(?:an?|the) /, '')) return compareTo(stripA, stripB);
    stripA = stripA.replace(/^(?:an?|the) /, '');
    stripB = stripB.replace(/^(?:an?|the) /, '');

    var seriesA, seriesB, subA, subB;
   if (stripA.indexOf(':') !== -1)
   {
       seriesA = stripA.split(':')[0];
       subA = stripA.substr(stripA.indexOf(':')+1);
   }
    else{seriesA = stripA; subA = '';}
   if (stripB.indexOf(':') !== -1)
   {
       seriesB = stripB.split(':')[0];
       subB = stripB.substr(stripB.indexOf(':')+1);
   }
    else{seriesB = stripB; subB = '';}

    var numberA, numberB;

    if((/\d+$/).test(seriesA)){numberA = parseInt((/ (\d+)$/).exec(seriesA)[1]); seriesA = seriesA.replace(/ \d+$/, '');}
    else numberA = -Infinity;
    if((/\d+$/).test(seriesB)){numberB = parseInt((/ (\d+)$/).exec(seriesB)[1]); seriesB = seriesB.replace(/ \d+$/, '');}
    else numberB = -Infinity;

    if(seriesA !== seriesB) return compareTo(seriesA, seriesB);
    if(numberA !== numberB) return compareTo(numberA, numberB);
    //only if from the same series. don't subtract due to -Infinity
    //note that if you have different numbering schemes then set numberA/B to the numeric value for comparison sake

    return compareTo(subA, subB);
    //see above for compareTo definition
}
//This one has too much meat for plain text so paste it into a syntax highlighter.

Saturday, September 20, 2014

Truly Random

There's a bit of a disagreement on whether true randomness exists but instead of going straight into what is randomness I'll have to take a round about path by starting with what people believe.

According to this youtube video: http://www.youtube.com/watch?v=dmX1W5umC1c science has determined that quantum physics is truly random ie it can never be predicted with certainty. I'll assume this is a true statement (ie science believes this). But Einstein isn't alone in his thoughts that "God does not roll dice", that is to say he is not alone in the theory that with enough data anything can be predicted with certainty so I'll group people based on this matter.

  1. People who believe in a god that knows the future with certainty and said god is the cause of all things. Do they believe truly random exists? No because god caused it, it isn't random.
  2. People who know quantum physics (and are not in group #1). Do they believe truly random exists? Yes because quantum stuff is truly random.
  3. Everyone else. Do they believe truly random exists? Maybe but probably not. General, simple science is calculated as though everything could be determined and that is how most people live their lives however some people also recognize things they can't explain and are therefore not sure if truly random exists.

But what defines truly random? A truly random event has an outcome (or occurrence) that can never be predicted. So obviously if god can predict it then it isn't truly random. However the common usage of the word random does not refer to truly random. For example: rolling a standard 6 sided die is considered random but it isn't truly random. Based on the initial spin, height, friction of table, air etc the die has only 1 possible outcome which could be calculated with certainty if a computer was given enough data and time to calculate it.

But if a 6 sided die is determined then why is it considered random at all? The common usage of the word random is referring to human observable random. Just like how truly random can never be predicted by anyone, human observable random is instead that it can't reasonably be predicted by humans. So, for example, a roulette wheel can't easily be calculated by a human to predict the outcome with certainty but a computer can (but only after it has been cast before it lands). This is where gambling comes in: "what do you think it will land on?" and also where cheating comes in: "what does the computer say it will land on?". To be more accurate I don't think computers are perfect at roulette it's just that they are so much better than a human that if you use one you'll get into big trouble.

Now there's also computers that generate random numbers based on an algorithm and a seed. Computers are completely deterministic: given the same seed will always give you the same answer. So then why is this considered random? Two reasons: 1) the algorithm used is hard to find and even if you do find it, it is hard to calculate by hand and 2) the same seed is never used again. The most obvious seed is the current time in milliseconds. Now this is not truly random and it is not always computer observable random however it is human observable random (and is therefore random via the common usage of the word). As a shout out to Java: java.util.Random uses the current time in nanoseconds as a seed making it impossible for a computer to cheat.

So what's with all the hate for random number generators? The first problem is that the average person doesn't know the difference between random and truly random and knowing that a computer is using a determined algorithm assumes that the results could be predicted by a human (which it can't) and is therefore unacceptable. The second problem is that not all random number generators are created equal: some older ones suck. I talked with a person who was playing Final Fantasy 1 (GBA remake) and the random number generator got stuck before he saved so that no matter what he did he met unavoidable death and had to start a new game. I've also heard that there was an old game (NES?) that didn't use time as the seed and was not hard for a human to calculate the entire battle ahead of time. Fortunately modern, well built random number generators don't have such problems and are safe and reliable. The third problem is that humans can't naturally understand statistics and sometimes make false claims (this is why we need education).

But I went off on a tangent. So is there such thing as random? Yes. Is there such thing as truly random? That depends on what you believe. So next time you say "lol I'm so random" I'll know what you really mean is "I act in a way that makes it difficult for other people to predict my actions."