Recently I came across an interesting place on the interwebs (via Twitter). Project Euler is a collection of challenging mathematical/computer programming problems that will require more than just mathematical insights to solve. The goal is to feed mathematical interested people’s hunger to learn and/or keep those people’s problem solving skills on the edge. And by doing so, you also get better insights in modern programming languages. Awesome… no?
Find the largest prime factor of the number 600851475143
I registered an account and solved 10 problems so far. And I must say… It’s more fun I’d have thought! You even get awards for solving specific problem sequences. I chose to tackle the problems using ActionScript 3, just because it’s a quick and nice language to mess around with. If you’re interested, I shared my solutions on Github. And here’s the ActionScript solution to the 3th Euler problem straight away
.
package {
import flash.display.Sprite;
public class EulerProblem003 extends Sprite {
public function EulerProblem003() {
super();
/*
The prime factors of 13195 are 5, 7, 13 and 29.
What is the largest prime factor of the
number 00851475143?
*/
// Start the algoritm by dividing with the
// smallest prime (=2).
divide(600851475143, 2);
}
private function divide(num:Number, prime:Number):void {
while (num % prime == 0) {
num = num / prime;
if (num == 1) {
trace("Result: " + prime);
return;
}
}
do {
prime++;
} while (!isPrime(prime));
divide(num, prime);
}
public function isPrime(num:Number):Boolean {
for (var i:Number = 3; i <= Math.sqrt(num); i += 2) {
if (num % i == 0) {
return false;
}
}
return (( num % 2 != 0 && num > 2) || num == 2);
}
}
}
Are you exited to try and solve a couple of problems too? Get yourself an account then! Off course you can also take a look at the problems first if you’d like
.














