day 5
This commit is contained in:
parent
4f65bd004d
commit
5d5e3f49f7
1
2018/05/input.txt
Normal file
1
2018/05/input.txt
Normal file
File diff suppressed because one or more lines are too long
30
2018/05/sol1.pl
Normal file
30
2018/05/sol1.pl
Normal file
@ -0,0 +1,30 @@
|
||||
use 5.20.0;
|
||||
use warnings;
|
||||
|
||||
use List::AllUtils qw/ uniq /;
|
||||
|
||||
use experimental qw/
|
||||
signatures
|
||||
postderef
|
||||
/;
|
||||
|
||||
my $code = <>;
|
||||
chomp $code;
|
||||
|
||||
use DDP;
|
||||
|
||||
say length react($code);
|
||||
|
||||
|
||||
sub react ($code) {
|
||||
my @combos = map { create_dual($_) } uniq split '', $code;
|
||||
my $re = join '|', @combos;
|
||||
|
||||
1 while $code =~ s/$re//g;
|
||||
|
||||
return $code;
|
||||
}
|
||||
|
||||
sub create_dual($x) {
|
||||
$x . ( $x eq uc $x ? lc $x : uc $x );
|
||||
}
|
33
2018/05/sol2.pl
Normal file
33
2018/05/sol2.pl
Normal file
@ -0,0 +1,33 @@
|
||||
use 5.20.0;
|
||||
use warnings;
|
||||
|
||||
use List::AllUtils qw/ uniq min /;
|
||||
|
||||
use experimental qw/
|
||||
signatures
|
||||
postderef
|
||||
/;
|
||||
|
||||
my $code = <>;
|
||||
chomp $code;
|
||||
|
||||
use DDP;
|
||||
|
||||
say min
|
||||
map { length react($_) }
|
||||
map { $code =~ s/$_//irg }
|
||||
'a'..'z';
|
||||
|
||||
|
||||
sub react ($code) {
|
||||
my @combos = map { create_dual($_) } uniq split '', $code;
|
||||
my $re = join '|', @combos;
|
||||
|
||||
1 while $code =~ s/$re//g;
|
||||
|
||||
return $code;
|
||||
}
|
||||
|
||||
sub create_dual($x) {
|
||||
$x . ( $x eq uc $x ? lc $x : uc $x );
|
||||
}
|
Loading…
Reference in New Issue
Block a user