Project Euler Problem 2

Problem 2, Brute Force again:

my $a = 1;
my $b = 2;
my $sum = 2;

while ($c<4000000) {
    $c = $a + $b;
    $sum += $c if $c%2==0;
    $a = $b;
    $b = $c;
}
print $sum;

Tinggalkan Balasan

Isikan data di bawah atau klik salah satu ikon untuk log in:

Logo WordPress.com

You are commenting using your WordPress.com account. Logout / Ubah )

Gambar Twitter

You are commenting using your Twitter account. Logout / Ubah )

Foto Facebook

You are commenting using your Facebook account. Logout / Ubah )

Foto Google+

You are commenting using your Google+ account. Logout / Ubah )

Connecting to %s