adventofcode/day2/day2b.pl
Yanick Champoux bc5be98a8d day2
2017-12-03 12:06:46 -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;
}
}