aboutsummaryrefslogtreecommitdiff
path: root/challenge-166/james-smith/perl
diff options
context:
space:
mode:
authordrbaggy <js5@sanger.ac.uk>2022-05-24 01:07:35 +0100
committerdrbaggy <js5@sanger.ac.uk>2022-05-24 01:07:35 +0100
commitd993f99473851fd32e5f9ec5a7ebbda2f22b67df (patch)
tree6bb90cbb61c1cff063a2ba7c65a9e664d574065d /challenge-166/james-smith/perl
parentc03c8411079c6277c7b1558f9c953d72ef439f4f (diff)
downloadperlweeklychallenge-club-d993f99473851fd32e5f9ec5a7ebbda2f22b67df.tar.gz
perlweeklychallenge-club-d993f99473851fd32e5f9ec5a7ebbda2f22b67df.tar.bz2
perlweeklychallenge-club-d993f99473851fd32e5f9ec5a7ebbda2f22b67df.zip
added in first pass at solutions
Diffstat (limited to 'challenge-166/james-smith/perl')
-rw-r--r--challenge-166/james-smith/perl/ch-1.pl23
-rw-r--r--challenge-166/james-smith/perl/ch-2.pl66
-rw-r--r--challenge-166/james-smith/perl/dir_a/Arial.ttf1
-rw-r--r--challenge-166/james-smith/perl/dir_a/Comic_Sans.ttf1
-rw-r--r--challenge-166/james-smith/perl/dir_a/Consolas.otf1
-rw-r--r--challenge-166/james-smith/perl/dir_a/Georgia.ttf1
-rw-r--r--challenge-166/james-smith/perl/dir_a/Helvetica.ttf1
-rw-r--r--challenge-166/james-smith/perl/dir_a/Impact.otf1
-rw-r--r--challenge-166/james-smith/perl/dir_a/Verdana.ttf1
-rw-r--r--challenge-166/james-smith/perl/dir_a/Wingdings.ttf1
-rw-r--r--challenge-166/james-smith/perl/dir_b/Arial.ttf1
-rw-r--r--challenge-166/james-smith/perl/dir_b/Comic_Sans.ttf1
-rw-r--r--challenge-166/james-smith/perl/dir_b/Consolas.otf1
-rw-r--r--challenge-166/james-smith/perl/dir_b/Courier_New.ttf1
-rw-r--r--challenge-166/james-smith/perl/dir_b/Helvetica.ttf1
-rw-r--r--challenge-166/james-smith/perl/dir_b/Impact.otf1
-rw-r--r--challenge-166/james-smith/perl/dir_b/Tahoma.ttf1
-rw-r--r--challenge-166/james-smith/perl/dir_b/Verdana.ttf1
-rw-r--r--challenge-166/james-smith/perl/dir_c/Arial.ttf1
-rw-r--r--challenge-166/james-smith/perl/dir_c/Consolas.otf1
-rw-r--r--challenge-166/james-smith/perl/dir_c/Courier_New.ttf1
-rw-r--r--challenge-166/james-smith/perl/dir_c/Helvetica.ttf1
-rw-r--r--challenge-166/james-smith/perl/dir_c/Impact.otf1
-rw-r--r--challenge-166/james-smith/perl/dir_c/Monaco.ttf1
-rw-r--r--challenge-166/james-smith/perl/dir_c/Verdana.ttf1
-rw-r--r--challenge-166/james-smith/perl/dir_d/Arial.ttf1
-rw-r--r--challenge-166/james-smith/perl/dir_d/Comic_Sans.ttf1
-rw-r--r--challenge-166/james-smith/perl/dir_d/Consolas.otf1
-rw-r--r--challenge-166/james-smith/perl/dir_d/Courier_New.ttf1
-rw-r--r--challenge-166/james-smith/perl/dir_d/Helvetica.ttf1
-rw-r--r--challenge-166/james-smith/perl/dir_d/Impact.otf1
-rw-r--r--challenge-166/james-smith/perl/dir_d/Monaco.ttf1
-rw-r--r--challenge-166/james-smith/perl/dir_d/Verdana.ttf1
-rw-r--r--challenge-166/james-smith/perl/dir_d/Wingdings.ttf1
34 files changed, 121 insertions, 0 deletions
diff --git a/challenge-166/james-smith/perl/ch-1.pl b/challenge-166/james-smith/perl/ch-1.pl
new file mode 100644
index 0000000000..4661645196
--- /dev/null
+++ b/challenge-166/james-smith/perl/ch-1.pl
@@ -0,0 +1,23 @@
+#!/usr/local/bin/perl
+
+use strict;
+
+use warnings;
+use feature qw(say);
+use Test::More;
+use Benchmark qw(cmpthese timethis);
+use Data::Dumper qw(Dumper);
+$Data::Dumper::Sortkeys = 1;
+my $re = 'abcdefoilst';
+my $words = [];
+while(<>) {
+ chomp;
+ next unless m{^[abcdefilostg]+$};
+ my $t = $_;
+ my $N = tr/oilstg/011579/;
+ warn "$N\t$t\t$_\n" if $N == length $_;
+ $words->[length $_]{$N}{$t}=$_;
+}
+
+print Dumper( $words );
+
diff --git a/challenge-166/james-smith/perl/ch-2.pl b/challenge-166/james-smith/perl/ch-2.pl
new file mode 100644
index 0000000000..a3e8947cf0
--- /dev/null
+++ b/challenge-166/james-smith/perl/ch-2.pl
@@ -0,0 +1,66 @@
+#!/usr/local/bin/perl
+
+use strict;
+
+use warnings;
+use feature qw(say);
+use Test::More;
+use Benchmark qw(cmpthese timethis);
+use Data::Dumper qw(Dumper);
+
+sub data {
+ return (
+ 'dir_a' => [sort qw(Arial.ttf Backup/ Comic_Sans.ttf Consolas.otf Georgia.ttf Helvetica.ttf Impact.otf Old_Fonts/ Verdana.ttf Wingdings.ttf)],
+ 'dir_b' => [sort qw(Arial.ttf Backup/ Comic_Sans.ttf Consolas.otf Courier_New.ttf Helvetica.ttf Impact.otf Tahoma.ttf Verdana.ttf)],
+ 'dir_c' => [sort qw(Arial.ttf Backup/ Consolas.otf Courier_New.ttf Helvetica.ttf Impact.otf Monaco.ttf Verdana.ttf)],
+ 'dir_d' => [sort qw(Arial.ttf Backup/ Comic_Sans.ttf Consolas.otf Courier_New.ttf Helvetica.ttf Impact.otf Monaco.ttf Verdana.ttf Wingdings.ttf)],
+ );
+}
+
+
+sub fetch {
+ my(%data,$f,$sh),opendir( my $dh, '.' );
+ opendir( $sh, $f=$_ ), $data{$f} = [ map { -d "$f/$_" ? "$_/" : $_ } grep { $_ ne '.' && $_ ne '..' } sort readdir $sh ]
+ for grep { -d $_ && $_ ne '.' && $_ ne '..' } readdir $dh;
+ %data;
+}
+k_diff( data ); kc( data );
+k_diff( fetch ); kc( fetch );
+
+sub k_diff {
+ my ($len,%dir,$F,$T) = (0,@_);
+
+ ## Get a sorted list of directory name & unique list of flies....
+ my %unique_files = map { $_ => 1 } map { @{$dir{$_}} } (my @paths = sort keys %dir);
+
+ ## Find the length of the longest directory/file name....
+ (length $_ > $len ) && ( $len = length $_ ) for @paths, keys %unique_files;
+
+ ## Create the template for printing a padded string & the line between header/body of table...
+ my $TEMPLATE = '|'." %-${len}s |" x @paths;
+ my $LINE = "+-@{[ join '-+-', map{ '-' x $len } @paths ]}-+";
+
+ ## Output results as a table with line - header - line - rows - line....
+ say $LINE;
+ say sprintf $TEMPLATE, @paths;
+ say $LINE;
+
+ ## Nasty and the meat of the display challenge.....
+ ## first line - checks to see if we have the line we have to display
+ ## second line - displays the files which are present
+ ## third line - if all the same shift them off the front of the lists...
+
+ $F = $_, ( grep { ($dir{$_}[0]//'') ne $F } @paths )
+ ? ( say sprintf $TEMPLATE, map { ($dir{$_}[0]//'') eq $F ? shift @{$dir{$_}} : '' } @paths )
+ : ( map { shift @{$dir{$_}} } @paths ) for sort keys %unique_files;
+
+ ## Just finish of the table!
+ say $LINE;
+}
+
+sub kc{my$l=0;my(%d,$F,@p,%u,$T,$L)=@_;
+(length$_>$l)&&($l=length$_)for(@p=sort keys%d),keys%{{%u=map{$_,1}map{@{$d{$_}}}@p}};
+say for($T='|'." %-${l}s |"x@p)x 0,$L="+-@{[join'-+-',map{'-'x$l}@p]}-+",sprintf($T,@p),$L,
+map({$F=$_;(grep{($d{$_}[0]//'')ne$F}@p)?(sprintf$T,map{($d{$_}[0]//'')eq$F?shift@{$d{$_}}:''}@p):
+map{shift@{$d{$_}};()}@p}sort keys%u),$L}
+
diff --git a/challenge-166/james-smith/perl/dir_a/Arial.ttf b/challenge-166/james-smith/perl/dir_a/Arial.ttf
new file mode 100644
index 0000000000..f70f10e4db
--- /dev/null
+++ b/challenge-166/james-smith/perl/dir_a/Arial.ttf
@@ -0,0 +1 @@
+A
diff --git a/challenge-166/james-smith/perl/dir_a/Comic_Sans.ttf b/challenge-166/james-smith/perl/dir_a/Comic_Sans.ttf
new file mode 100644
index 0000000000..3cc58df837
--- /dev/null
+++ b/challenge-166/james-smith/perl/dir_a/Comic_Sans.ttf
@@ -0,0 +1 @@
+C
diff --git a/challenge-166/james-smith/perl/dir_a/Consolas.otf b/challenge-166/james-smith/perl/dir_a/Consolas.otf
new file mode 100644
index 0000000000..3cc58df837
--- /dev/null
+++ b/challenge-166/james-smith/perl/dir_a/Consolas.otf
@@ -0,0 +1 @@
+C
diff --git a/challenge-166/james-smith/perl/dir_a/Georgia.ttf b/challenge-166/james-smith/perl/dir_a/Georgia.ttf
new file mode 100644
index 0000000000..fd79235298
--- /dev/null
+++ b/challenge-166/james-smith/perl/dir_a/Georgia.ttf
@@ -0,0 +1 @@
+G
diff --git a/challenge-166/james-smith/perl/dir_a/Helvetica.ttf b/challenge-166/james-smith/perl/dir_a/Helvetica.ttf
new file mode 100644
index 0000000000..a9edc74f38
--- /dev/null
+++ b/challenge-166/james-smith/perl/dir_a/Helvetica.ttf
@@ -0,0 +1 @@
+H
diff --git a/challenge-166/james-smith/perl/dir_a/Impact.otf b/challenge-166/james-smith/perl/dir_a/Impact.otf
new file mode 100644
index 0000000000..db1a5a09f7
--- /dev/null
+++ b/challenge-166/james-smith/perl/dir_a/Impact.otf
@@ -0,0 +1 @@
+I
diff --git a/challenge-166/james-smith/perl/dir_a/Verdana.ttf b/challenge-166/james-smith/perl/dir_a/Verdana.ttf
new file mode 100644
index 0000000000..67e997e40b
--- /dev/null
+++ b/challenge-166/james-smith/perl/dir_a/Verdana.ttf
@@ -0,0 +1 @@
+V
diff --git a/challenge-166/james-smith/perl/dir_a/Wingdings.ttf b/challenge-166/james-smith/perl/dir_a/Wingdings.ttf
new file mode 100644
index 0000000000..a42d8ff619
--- /dev/null
+++ b/challenge-166/james-smith/perl/dir_a/Wingdings.ttf
@@ -0,0 +1 @@
+W
diff --git a/challenge-166/james-smith/perl/dir_b/Arial.ttf b/challenge-166/james-smith/perl/dir_b/Arial.ttf
new file mode 100644
index 0000000000..f70f10e4db
--- /dev/null
+++ b/challenge-166/james-smith/perl/dir_b/Arial.ttf
@@ -0,0 +1 @@
+A
diff --git a/challenge-166/james-smith/perl/dir_b/Comic_Sans.ttf b/challenge-166/james-smith/perl/dir_b/Comic_Sans.ttf
new file mode 100644
index 0000000000..3cc58df837
--- /dev/null
+++ b/challenge-166/james-smith/perl/dir_b/Comic_Sans.ttf
@@ -0,0 +1 @@
+C
diff --git a/challenge-166/james-smith/perl/dir_b/Consolas.otf b/challenge-166/james-smith/perl/dir_b/Consolas.otf
new file mode 100644
index 0000000000..3cc58df837
--- /dev/null
+++ b/challenge-166/james-smith/perl/dir_b/Consolas.otf
@@ -0,0 +1 @@
+C
diff --git a/challenge-166/james-smith/perl/dir_b/Courier_New.ttf b/challenge-166/james-smith/perl/dir_b/Courier_New.ttf
new file mode 100644
index 0000000000..3cc58df837
--- /dev/null
+++ b/challenge-166/james-smith/perl/dir_b/Courier_New.ttf
@@ -0,0 +1 @@
+C
diff --git a/challenge-166/james-smith/perl/dir_b/Helvetica.ttf b/challenge-166/james-smith/perl/dir_b/Helvetica.ttf
new file mode 100644
index 0000000000..a9edc74f38
--- /dev/null
+++ b/challenge-166/james-smith/perl/dir_b/Helvetica.ttf
@@ -0,0 +1 @@
+H
diff --git a/challenge-166/james-smith/perl/dir_b/Impact.otf b/challenge-166/james-smith/perl/dir_b/Impact.otf
new file mode 100644
index 0000000000..db1a5a09f7
--- /dev/null
+++ b/challenge-166/james-smith/perl/dir_b/Impact.otf
@@ -0,0 +1 @@
+I
diff --git a/challenge-166/james-smith/perl/dir_b/Tahoma.ttf b/challenge-166/james-smith/perl/dir_b/Tahoma.ttf
new file mode 100644
index 0000000000..62a6e3c9df
--- /dev/null
+++ b/challenge-166/james-smith/perl/dir_b/Tahoma.ttf
@@ -0,0 +1 @@
+T
diff --git a/challenge-166/james-smith/perl/dir_b/Verdana.ttf b/challenge-166/james-smith/perl/dir_b/Verdana.ttf
new file mode 100644
index 0000000000..67e997e40b
--- /dev/null
+++ b/challenge-166/james-smith/perl/dir_b/Verdana.ttf
@@ -0,0 +1 @@
+V
diff --git a/challenge-166/james-smith/perl/dir_c/Arial.ttf b/challenge-166/james-smith/perl/dir_c/Arial.ttf
new file mode 100644
index 0000000000..f70f10e4db
--- /dev/null
+++ b/challenge-166/james-smith/perl/dir_c/Arial.ttf
@@ -0,0 +1 @@
+A
diff --git a/challenge-166/james-smith/perl/dir_c/Consolas.otf b/challenge-166/james-smith/perl/dir_c/Consolas.otf
new file mode 100644
index 0000000000..3cc58df837
--- /dev/null
+++ b/challenge-166/james-smith/perl/dir_c/Consolas.otf
@@ -0,0 +1 @@
+C
diff --git a/challenge-166/james-smith/perl/dir_c/Courier_New.ttf b/challenge-166/james-smith/perl/dir_c/Courier_New.ttf
new file mode 100644
index 0000000000..3cc58df837
--- /dev/null
+++ b/challenge-166/james-smith/perl/dir_c/Courier_New.ttf
@@ -0,0 +1 @@
+C
diff --git a/challenge-166/james-smith/perl/dir_c/Helvetica.ttf b/challenge-166/james-smith/perl/dir_c/Helvetica.ttf
new file mode 100644
index 0000000000..a9edc74f38
--- /dev/null
+++ b/challenge-166/james-smith/perl/dir_c/Helvetica.ttf
@@ -0,0 +1 @@
+H
diff --git a/challenge-166/james-smith/perl/dir_c/Impact.otf b/challenge-166/james-smith/perl/dir_c/Impact.otf
new file mode 100644
index 0000000000..db1a5a09f7
--- /dev/null
+++ b/challenge-166/james-smith/perl/dir_c/Impact.otf
@@ -0,0 +1 @@
+I
diff --git a/challenge-166/james-smith/perl/dir_c/Monaco.ttf b/challenge-166/james-smith/perl/dir_c/Monaco.ttf
new file mode 100644
index 0000000000..ab7768987c
--- /dev/null
+++ b/challenge-166/james-smith/perl/dir_c/Monaco.ttf
@@ -0,0 +1 @@
+M
diff --git a/challenge-166/james-smith/perl/dir_c/Verdana.ttf b/challenge-166/james-smith/perl/dir_c/Verdana.ttf
new file mode 100644
index 0000000000..67e997e40b
--- /dev/null
+++ b/challenge-166/james-smith/perl/dir_c/Verdana.ttf
@@ -0,0 +1 @@
+V
diff --git a/challenge-166/james-smith/perl/dir_d/Arial.ttf b/challenge-166/james-smith/perl/dir_d/Arial.ttf
new file mode 100644
index 0000000000..f70f10e4db
--- /dev/null
+++ b/challenge-166/james-smith/perl/dir_d/Arial.ttf
@@ -0,0 +1 @@
+A
diff --git a/challenge-166/james-smith/perl/dir_d/Comic_Sans.ttf b/challenge-166/james-smith/perl/dir_d/Comic_Sans.ttf
new file mode 100644
index 0000000000..3cc58df837
--- /dev/null
+++ b/challenge-166/james-smith/perl/dir_d/Comic_Sans.ttf
@@ -0,0 +1 @@
+C
diff --git a/challenge-166/james-smith/perl/dir_d/Consolas.otf b/challenge-166/james-smith/perl/dir_d/Consolas.otf
new file mode 100644
index 0000000000..3cc58df837
--- /dev/null
+++ b/challenge-166/james-smith/perl/dir_d/Consolas.otf
@@ -0,0 +1 @@
+C
diff --git a/challenge-166/james-smith/perl/dir_d/Courier_New.ttf b/challenge-166/james-smith/perl/dir_d/Courier_New.ttf
new file mode 100644
index 0000000000..3cc58df837
--- /dev/null
+++ b/challenge-166/james-smith/perl/dir_d/Courier_New.ttf
@@ -0,0 +1 @@
+C
diff --git a/challenge-166/james-smith/perl/dir_d/Helvetica.ttf b/challenge-166/james-smith/perl/dir_d/Helvetica.ttf
new file mode 100644
index 0000000000..a9edc74f38
--- /dev/null
+++ b/challenge-166/james-smith/perl/dir_d/Helvetica.ttf
@@ -0,0 +1 @@
+H
diff --git a/challenge-166/james-smith/perl/dir_d/Impact.otf b/challenge-166/james-smith/perl/dir_d/Impact.otf
new file mode 100644
index 0000000000..db1a5a09f7
--- /dev/null
+++ b/challenge-166/james-smith/perl/dir_d/Impact.otf
@@ -0,0 +1 @@
+I
diff --git a/challenge-166/james-smith/perl/dir_d/Monaco.ttf b/challenge-166/james-smith/perl/dir_d/Monaco.ttf
new file mode 100644
index 0000000000..ab7768987c
--- /dev/null
+++ b/challenge-166/james-smith/perl/dir_d/Monaco.ttf
@@ -0,0 +1 @@
+M
diff --git a/challenge-166/james-smith/perl/dir_d/Verdana.ttf b/challenge-166/james-smith/perl/dir_d/Verdana.ttf
new file mode 100644
index 0000000000..67e997e40b
--- /dev/null
+++ b/challenge-166/james-smith/perl/dir_d/Verdana.ttf
@@ -0,0 +1 @@
+V
diff --git a/challenge-166/james-smith/perl/dir_d/Wingdings.ttf b/challenge-166/james-smith/perl/dir_d/Wingdings.ttf
new file mode 100644
index 0000000000..a42d8ff619
--- /dev/null
+++ b/challenge-166/james-smith/perl/dir_d/Wingdings.ttf
@@ -0,0 +1 @@
+W