Thursday 12 April 2012

Simultaneous Equations?

I realised today just how important maths can be for programming.
Based on my experience with my new Mastering Mathematics book it really does astound me that we are not taught algebra in University.
I suppose most students going to university have been in education for a while so algebra is still fresh in their mind, but it has been more than five years since I studied the subject.

One of the exercises was something called Arithmogons:
The numbers in the square are the sum of the circles on each side of the square.
I initially assumed they were whole numbers and was getting nowhere.
I decided I needed to employ some algebra.

I wrote out a formula like this:
27 is the sum of all squares:
27=(X+Z)+(X+Y)+(Z+Y)
I ended up with:
27-Z = X+Z
-----
  Y

That is 27 minus Z over Y is equal to X plus Z.
I assumed I needed to multiply X plus Z and decided this was the wrong approach.
Instead I asked my housemate how he would approach it and he came up with the following solution:

X+Y=8
Y+Z=9
X+Z=10

(9-Y)+2=10
Z=10-(8-Y)
y+10-(8-Y)=9
Y+2+Y=9
2Y=7
Y=3.5

I recognised a bit of this from simultaneous equations and proceeded to repeat the word several times and then we both moaned about how boring maths was in school.

Now that I had an algorithm for working out X,Y and Z I could write a program.
This is why whenever my tutors say programmers don't need to learn maths, I completely ignore them and continue reading my awesome book.

No comments:

Post a Comment