day12
This commit is contained in:
parent
424e0310af
commit
592efaf1af
20
2015/12/a.pl
Normal file
20
2015/12/a.pl
Normal file
@ -0,0 +1,20 @@
|
||||
use 5.20.0;
|
||||
|
||||
use List::AllUtils qw/ sum /;
|
||||
use File::Serialize;
|
||||
|
||||
use experimental 'signatures', 'smartmatch';
|
||||
|
||||
my $data = deserialize_file shift;
|
||||
|
||||
say add($data);
|
||||
|
||||
sub add($data) {
|
||||
given ( ref $data ) {
|
||||
return sum map { add($_) } @$data when 'ARRAY';
|
||||
return sum map { add($_) } values %$data when 'HASH';
|
||||
default { return 0 + $data };
|
||||
}
|
||||
}
|
||||
|
||||
|
20
2015/12/b.pl
Normal file
20
2015/12/b.pl
Normal file
@ -0,0 +1,20 @@
|
||||
use 5.20.0;
|
||||
|
||||
use List::AllUtils qw/ sum /;
|
||||
use File::Serialize;
|
||||
|
||||
use experimental 'signatures', 'smartmatch';
|
||||
|
||||
my $data = deserialize_file shift;
|
||||
|
||||
say add($data);
|
||||
|
||||
sub add($data) {
|
||||
given ( ref $data ) {
|
||||
return sum map { add($_) } @$data when 'ARRAY';
|
||||
return ( ( grep { $_ eq 'red' } values %$data ) ? 0 : 1) * sum map { add($_) } values %$data when 'HASH';
|
||||
default { return 0 + $data };
|
||||
}
|
||||
}
|
||||
|
||||
|
1
2015/12/input.json
Normal file
1
2015/12/input.json
Normal file
File diff suppressed because one or more lines are too long
Loading…
Reference in New Issue
Block a user