That there are quite a few ways to generate Pythagorean Triples. How did I acquire this piece of information?

I was trying to solve Problem Nine of Project Euler.

The first method I considered was the one I learnt in school. I realised it was hopelessly inefficient. The method involved running three loops, each nested within the other. It would iterate trying to find three numbers that would fulfill the condition for Pythagorean Triples ( a^{2} + b^{2} = c^{2}). It would take too long to find a triple that fulfilled the condition.

I then went to Wikipedia to find other ways to generate triples. I realised there were a fair bunch. In the end, I settled for Euclid’s Formula ( a = 2mn : b = m^{2} – n^{2} : c = m^{2} + n^{2} ) It gave me the answer in under a minute.

<rant>

I was never taught any of those methods in school. Not even in Mathematics class. Why not? The only thing they ever taught us was what was a Pythagorean Triple. And in Computer Science, why teach us such an inefficient method? I wonder if my teacher knew any other method. Probably not. Bloody System.

</rant>

I like project Euler. A Lot.

Also Wikipedia.

I’m now looking for an efficient way to determine the Primality of a number **n**. Dividing by all numbers less than √n might be inefficient for a range of two million. The AKS Primality Test looks promising. Now I just have to understand it.

### Like this:

Like Loading...

*Related*

August 31, 2008 at 11:03 pm

HOW on earth are u suddenly in love wid maths ???????

September 4, 2008 at 4:05 am

Mate. i echo your sis’ concern. what went wrong? π

let us rescue you dude. it *hurts* to see you in such a low state.

*Loving Maths!* Oh Dear Dear

September 5, 2008 at 11:20 am

one of the automatically generated possibly related posts says “How to kill a Human Being.”

π

this is what blogging about math does, methinks.

September 14, 2008 at 4:10 pm

It’s funny. Couple of nights ago, I had a dream that I had a maths test the next day, and I didn’t have a fucking clue about how to do any of the sums in the syllabus. I woke up sweating in an air conditioned room. And you’re doing maths for fun π

But it’s good mate. Sharpening your mind and all that. English honours is sometimes such a load of bullshit it must be refreshing to challenge your mind in tangible ways, from time to time.

September 15, 2008 at 9:28 am

You like doing maths. Heh.

Gives me the creeps.

October 22, 2008 at 12:08 pm

Listen.You are altogether admirable, not of course as Prayag says, we are up to a lot of bullshit, but because, you are keeping your brain very very alive.

I sharpen pencils. It’s goodstuff.

October 23, 2008 at 8:04 pm

Ha ha. I am sure.