The Sum Of Two Squares

0

Programming Praxis

If you like to program math puzzles, you probably know about Project Euler; in fact, it was that site that inspired Programming Praxis. We don’t usually do math puzzles here, because Project Euler does them better, but the occasional math puzzle can be entertaining, and lead to some fun programming. Hence, today’s exercise.

Your task is to write a function that, given a number n, finds all pairs of numbers x and y, with x ? y ? 0, such that x + y = n; for instance, 50 = 7 + 1 = 5 + 5, 48612265 = 6972 + 59 = 6971 + 132 = ?, and 999 has no solutions. When you are finished, you are welcome to read or run a suggested solution, or to post your own solution or discuss the exercise in the comments below.

Brute force search over all…

View original post 438 more words