day2
This commit is contained in:
parent
cd464e9d65
commit
bc5be98a8d
7
day2/day2.pl
Executable file
7
day2/day2.pl
Executable 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
14
day2/day2b.pl
Executable 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;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user