adventofcode/2017/day2/day2b.pl
2017-12-28 12:14:51 -05:00

15 lines
297 B
Perl
Executable File

#!/usr/bin/perl
use 5.20.0;
use experimental 'signatures';
use List::AllUtils qw/ sum first /;
say sum map { divisors( sort { $b <=> $a } split ) } <>;
sub divisors(@nums) {
while( my $x = shift @nums ) {
return $x / $_ for grep { defined $_ } first { not $x % $_ } @nums;
}
}