adventofcode/2017/day2/day2b.pl

15 lines
297 B
Perl
Raw Normal View History

2017-12-03 17:06:46 +00:00
#!/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;
}
}