days 5-11

This commit is contained in:
Ben Charlton 2018-12-11 21:39:38 +00:00
parent d3ae65f625
commit 1d2d5def97
18 changed files with 804 additions and 0 deletions

23
5/1-2.pl Normal file
View file

@ -0,0 +1,23 @@
#!/usr/bin/perl
use strict;
use v5.10;
use Data::Dumper;
chomp (my @data = <STDIN>);
@data = sort @data;
my @remove;
foreach my $c ('a'..'z') {
push @remove, ($c . uc($c)), (uc($c) . $c);
}
my $remove = join("|", @remove);
foreach my $line (@data) {
say $line;
while ( $line =~ s/($remove)//ge ) {
}
say $line . " " . length($line);
}

37
5/1.pl Normal file
View file

@ -0,0 +1,37 @@
#!/usr/bin/perl
use strict;
use v5.10;
use Data::Dumper;
chomp (my @data = <STDIN>);
@data = sort @data;
foreach my $line (@data) {
say $line;
my @line = split //, $line;
my $pos = 0;
say $pos, "/", $#line;
while ( $pos < $#line ) {
if (($line[$pos] =~ m/[A-Z]/) && ( lc($line[$pos]) eq $line[$pos+1] )
|| ($line[$pos] =~ m/[a-z]/) && ( uc($line[$pos]) eq $line[$pos+1] )) {
#say "Cancelling ", $line[$pos], $line[$pos+1];
# Urgh, this is slow.
if ($pos > 0) {
@line = (@line[ 0..$pos-1 ], @line[ $pos+2 .. $#line ]);
} else {
@line = @line[ $pos+2 .. $#line ];
}
$pos--;
} else {
$pos++;
}
}
say join("", @line);
print ($#line + 1);
}

34
5/2.pl Normal file
View file

@ -0,0 +1,34 @@
#!/usr/bin/perl
use strict;
use v5.10;
use Data::Dumper;
chomp (my @data = <STDIN>);
@data = sort @data;
my @remove;
foreach my $c ('a'..'z') {
push @remove, ($c . uc($c)), (uc($c) . $c);
}
my $remove = join("|", @remove);
foreach my $line (@data) {
say $line;
my $min = length($line);
foreach my $c ('a'..'z') {
my $test = $line;
say $test . " " . length($test);
my $pre = $c . "|" . uc($c);
$test =~ s/($pre)//ge;
while ( $test =~ s/($remove)//ge ) {
}
if (length($test) < $min) {
$min = length($test);
}
say $pre . " " . $test . " " . length($test);
}
say $min;
}

1
5/sample.txt Normal file
View file

@ -0,0 +1 @@
dabAcCaCBAcCcaDA