challenges

my solutions to various "programming challenge" problems
git clone https://wehaveforgeathome.hates.computer/challenges.git
Log | Files | Refs | LICENSE

001.pl (368B)


      1 #!/usr/bin/perl
      2 
      3 use strict;
      4 use warnings;
      5 
      6 my $threes = 0;
      7 for (my $i = 0; $i < 1000; $i += 3) {
      8   $threes += $i;
      9 }
     10 
     11 my $fives = 0;
     12 for (my $i = 0; $i < 1000; $i += 5) {
     13   $fives += $i;
     14 }
     15 
     16 # multiples of 15 will get counted twice
     17 my $fifteens = 0;
     18 for (my $i = 0; $i < 1000; $i += 15) {
     19   $fifteens += $i;
     20 }
     21 
     22 my $sum += $threes + $fives - $fifteens;
     23 
     24 print "$sum\n";