Sunday, February 23, 2014

Perl solution to Project Euler's problem #1

#!/usr/local/bin/perl
$sum = 0;
for $i (1 .. 999) {
   if(($i % 3) == 0){
      $sum += $i;
   }
   else 
   {
    if(($i % 5) == 0){
    $sum += $i;
    }
   }
}

print $sum;

https://ideone.com/5NrFot

No comments: