This commit is contained in:
Yanick Champoux 2017-12-03 12:06:46 -05:00
parent cd464e9d65
commit bc5be98a8d
2 changed files with 21 additions and 0 deletions

7
day2/day2.pl Executable file
View File

@ -0,0 +1,7 @@
#!/usr/bin/perl
use 5.20.0;
use List::AllUtils qw/ minmax sum pairmap /;
say sum pairmap { -$a, $b } map { minmax split } <>;

14
day2/day2b.pl Executable file
View File

@ -0,0 +1,14 @@
#!/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;
}
}