That there are quite a few ways to generate Pythagorean Triples. How did I acquire this piece of information?
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 ( a2 + b2 = c2). 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 = m2 – n2 : c = m2 + n2 ) It gave me the answer in under a minute.
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.
I like project Euler. A Lot.
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.