# aoc2015

Advent of Code 2015 solutions in Perl.
git clone git://git.samirparikh.com/aoc2015
Log | Files | Refs | README

```commit 0cece4b6c7ecf0670a0f9fb616dd9e96c0ff9a9e
parent a187095cec4c0a1409d595d7ca6e37158d0065d3
Date:   Sat, 12 Nov 2022 16:58:37 +0000

solve part 2 of day20

Diffstat:
Mday20/day20.pl | 39+++++----------------------------------
```
```1 file changed, 5 insertions(+), 34 deletions(-)
diff --git a/day20/day20.pl b/day20/day20.pl
@@ -4,7 +4,6 @@
use strict;
use warnings;
use v5.32;
-use lib '.';
use Math::Prime::Util qw( divisors );
use List::Util        qw( sum );

@@ -14,41 +13,13 @@ my \$house_number = 1;
\$house_number++ while ( sum( divisors( \$house_number ) ) * 10 < \$input );
say "part 1: ", \$house_number;

-
-#my \$NUM_ELVES = 8;
my \$MAX_HOUSES = 50;
my \$PRESENTS_PER_HOUSE = 11;
-my %presents;
-my \$target = 400;
-my \$elf = 1;
+\$house_number = 1;

-#foreach my \$elf ( 1 .. \$NUM_ELVES ) {
while (1) {
-    my \$house_number = \$elf;
-    foreach my \$house ( 1 .. \$MAX_HOUSES ) {
-        print "elf \$elf is delivering ", \$elf * \$PRESENTS_PER_HOUSE, " presents to house \$house_number ";
-        \$presents{ \$house_number } += \$elf * \$PRESENTS_PER_HOUSE;
-        say "which now has \$presents{\$house_number} presents";
-        if ( \$presents{ \$house_number } >= \$input ) {
-            say "part 2: ", \$house_number;
-            exit;
-        }
-        \$house_number += \$elf;
-    }
-    \$elf++;
+    my \$presents = \$PRESENTS_PER_HOUSE * sum(grep { \$_ >= \$house_number/\$MAX_HOUSES } divisors(\$house_number));
+    last if \$presents >= \$input;
+    \$house_number++;
}
-
-
-#foreach my \$elf ( 1 .. \$NUM_ELVES ) {
-#    my \$house_number = \$elf;
-#    foreach my \$house ( 1 .. \$MAX_HOUSES ) {
-#        print "elf \$elf is delivering ", \$house_number * \$PRESENTS_PER_HOUSE, " presents to house \$house_number ";
-#        \$presents{ \$house_number } += \$house_number * \$PRESENTS_PER_HOUSE;
-#        say "which now has \$presents{\$house_number} presents";
-#        if ( \$presents{ \$house_number } > \$target ) {
-#            say "part 2: ", \$house_number;
-#            exit;
-#        }
-#        \$house_number += \$elf;
-#    }
-#}
+say "part 2: ", \$house_number;
```