2016-04
This commit is contained in:
parent
fa621a4d25
commit
64fc6fade0
17
2016/04/1.pl
Normal file
17
2016/04/1.pl
Normal file
@ -0,0 +1,17 @@
|
||||
use 5.20.0;
|
||||
|
||||
use List::UtilsBy qw/ sort_by /;
|
||||
use List::AllUtils qw/ sum /;
|
||||
use experimental qw/ signatures /;
|
||||
|
||||
|
||||
say sum map { /(\d+)/ } grep { is_real($_) } <>;
|
||||
|
||||
sub is_real ( $line ) {
|
||||
$line =~ s/\[(.*?)\]//;
|
||||
my $checksum = $1;
|
||||
|
||||
$checksum eq join '', ( sort_by {
|
||||
sprintf "%03d%s", 999 - (eval "\$line =~ y/$_/$_/"), $_
|
||||
} 'a'..'z' )[0..4];
|
||||
}
|
32
2016/04/2.pl
Normal file
32
2016/04/2.pl
Normal file
@ -0,0 +1,32 @@
|
||||
use 5.20.0;
|
||||
|
||||
use List::UtilsBy qw/ sort_by /;
|
||||
use List::AllUtils qw/ sum /;
|
||||
use experimental qw/ signatures /;
|
||||
|
||||
my @real = grep { is_real($_) } <>;
|
||||
|
||||
my @alphabet = ( 'a'..'z' );
|
||||
say $_, ": ", decrypt($_) for @real;
|
||||
|
||||
|
||||
sub decrypt($line) {
|
||||
|
||||
$line =~ s/(\d+).*$//;
|
||||
my $checksum = $1;
|
||||
|
||||
$line =~ s/-/ /g;
|
||||
$line =~ s/([a-z])/ $alphabet[ ( ord( $1 ) - ord( 'a' ) + $checksum ) % @alphabet ]/eg;
|
||||
|
||||
$line;
|
||||
|
||||
}
|
||||
|
||||
sub is_real ( $line ) {
|
||||
$line =~ s/\[(.*?)\]//;
|
||||
my $checksum = $1;
|
||||
|
||||
$checksum eq join '', ( sort_by {
|
||||
sprintf "%03d%s", 999 - (eval "\$line =~ y/$_/$_/"), $_
|
||||
} 'a'..'z' )[0..4];
|
||||
}
|
Loading…
Reference in New Issue
Block a user