Friday, February 18, 2011

I Heart Algebra

Ahh. It's my first day back in dear, sweet Algebra, and I've already realized why I missed it so much. Unlike geometry, it's practical. Sure, I can see where geometry would be useful to a surveyor, architect, pool player, or some other such geometrically-inclined professional, but Algebra is actually applicable to me, now.

For instance, take this supposedly illogical math problem:

x = x + 1

Wait just a second! you say. At first glance, this problem looks impossible. It doesn't take a math whiz to realize that any number plus one will no longer equal itself. Oh, but wait. Herein lies the beauty of math.

To demonstrate the problem in its application, let's pretend we are going to create a simple text-based computer game using visual basic. To beat the game, you have to answer three questions correctly in a row. "X" is defined as the number of correctly answered questions. At the beginning of the game, the player has zero correct answers.

x = 0

The player launches the game, and he or she is presented with one of various pre-defined randomly selected questions. In this example, the first question is "What is the capital of Djibouti?" The correct answer is Djibouti. The code for this particular question would look something like this:

answer = inputbox("What is the capital of Djibouti?")
       if answer = "Djibouti" then
       AddScore()
             else
       Reset()

If the answer is anything other than "Djibouti" (aka if the answer is wrong), the player is sent to the function Reset(). In this case, Reset() consists of little more than x = 0. This (gasp!) resets the player's score to 0, no matter what. Reset() then sends the player back to the questionaire function.

If the answer is correct, the player is sent to AddScore(), which contains that tricky little math problem we discussed at the beginning of this post.

x = x + 1

This is read as "the value of x is equal to the previous value of x plus one". Remember, x was set to 0 at the launch of the game. The script will therefore interpret the problem as follows:

x = 0 + 1 (or) x = 1

In our game, AddScore() also checks if three questions have been correctly answered in a row.

if x = 3 then
       WinGame()
             else
       Questionaire()

If the number of correctly answered questions is equal to three, a congratulating message will appear. If not, the game loops back to the question function. In our case, the value of x is only equal to one, so we must ask the player more questions.

Pretend the player answers the next question correctly. The code in function AddScore() still reads x = x + 1, but now the program interprets it as:

x = 1 + 1 (or) x = 2

Because x does not equal three, the function loops back to Questionaire() and asks another question. If the player answers the next question incorrectly, x resets to 0 and he or she must start from scratch. In this case, we'll pretend that the player has answered their third question correctly. x = x + 1 is now interpreted as:

x = 2 + 1 (or) x = 3

X is now equal to three, so the player wins! This is a rough example of how an algebraic problem can be applied in a computer program, but you get the general idea.

Yes, I know what you're thinking. I'm a total, complete dork. I won't deny that. And I won't stop loving Algebra. <3

No comments:

Post a Comment