aboutsummaryrefslogtreecommitdiff
path: root/challenge-166
diff options
context:
space:
mode:
authorMohammad S Anwar <mohammad.anwar@yahoo.com>2022-05-30 00:58:16 +0100
committerMohammad S Anwar <mohammad.anwar@yahoo.com>2022-05-30 00:58:16 +0100
commit1682f9141c42d02acba287cac8adc51f4deb9f84 (patch)
tree09be25a47602dbdbcb2e7ae1fbe665231e260d01 /challenge-166
parent4139dd865e502ce4e192389fa58f41811ba3d4e7 (diff)
downloadperlweeklychallenge-club-1682f9141c42d02acba287cac8adc51f4deb9f84.tar.gz
perlweeklychallenge-club-1682f9141c42d02acba287cac8adc51f4deb9f84.tar.bz2
perlweeklychallenge-club-1682f9141c42d02acba287cac8adc51f4deb9f84.zip
- Added solutions by Laurent Rosenfeld.
Diffstat (limited to 'challenge-166')
-rw-r--r--challenge-166/laurent-rosenfeld/blog.txt1
-rw-r--r--challenge-166/laurent-rosenfeld/perl/ch-1.pl12
-rw-r--r--challenge-166/laurent-rosenfeld/perl/ch-1a.pl16
-rw-r--r--challenge-166/laurent-rosenfeld/perl/ch-2.pl24
-rw-r--r--challenge-166/laurent-rosenfeld/raku/ch-1.raku5
-rw-r--r--challenge-166/laurent-rosenfeld/raku/ch-1a.raku9
-rw-r--r--challenge-166/laurent-rosenfeld/raku/ch-2.raku11
7 files changed, 78 insertions, 0 deletions
diff --git a/challenge-166/laurent-rosenfeld/blog.txt b/challenge-166/laurent-rosenfeld/blog.txt
new file mode 100644
index 0000000000..450c89c0f1
--- /dev/null
+++ b/challenge-166/laurent-rosenfeld/blog.txt
@@ -0,0 +1 @@
+http://blogs.perl.org/users/laurent_r/2022/05/perl-weekly-challenge-166-hexadecimal-words-and-k-directory-diff.html
diff --git a/challenge-166/laurent-rosenfeld/perl/ch-1.pl b/challenge-166/laurent-rosenfeld/perl/ch-1.pl
new file mode 100644
index 0000000000..11cc6b949b
--- /dev/null
+++ b/challenge-166/laurent-rosenfeld/perl/ch-1.pl
@@ -0,0 +1,12 @@
+use strict;
+use warnings;
+use feature "say";
+
+my $file_in = "./words.txt";
+open my $IN, "<", $file_in or die "unable to open $file_in";
+while (my $line = <$IN>) {
+ chomp $line;
+ next if length $line < 2 or length $line > 8;
+ next if $line =~ /[^a-folist]/;
+ say "$_ -> 0x", tr/olist/01157/r for $line;
+}
diff --git a/challenge-166/laurent-rosenfeld/perl/ch-1a.pl b/challenge-166/laurent-rosenfeld/perl/ch-1a.pl
new file mode 100644
index 0000000000..e187d22abb
--- /dev/null
+++ b/challenge-166/laurent-rosenfeld/perl/ch-1a.pl
@@ -0,0 +1,16 @@
+use strict;
+use warnings;
+use feature "say";
+
+my $max = shift;
+$max = 4 unless defined $max;
+my $file_in = "./words.txt";
+open my $IN, "<", $file_in or die "unable to open $file_in";
+while (my $line = <$IN>) {
+ chomp $line;
+ next if length $line < 2 or length $line > 8;
+ next if $line =~ /[^a-folist]/;
+ my $word = $line;
+ next if ($word =~ tr/olist/01157/) > $max;
+ say $line, " -> 0x", $word;
+}
diff --git a/challenge-166/laurent-rosenfeld/perl/ch-2.pl b/challenge-166/laurent-rosenfeld/perl/ch-2.pl
new file mode 100644
index 0000000000..f2bef5fb56
--- /dev/null
+++ b/challenge-166/laurent-rosenfeld/perl/ch-2.pl
@@ -0,0 +1,24 @@
+use strict;
+use warnings;
+use feature "say";
+
+my @dirs = glob("./rootdir/*");
+my $nb_dirs = scalar @dirs;
+my %dircontent;
+for my $dir (@dirs) {
+ $dircontent{$dir} = [ map {/(\w+$)/} glob "$dir/*" ];
+}
+say "Contents of the directories: ";
+for my $dir (@dirs) {
+ say "$dir: ", join " ", @{$dircontent{$dir}}
+}
+
+my %files;
+for my $dir (@dirs) {
+ $files{$_}++ for @{$dircontent{$dir}}
+}
+say "\nCommon files: ", join " ", grep { $files{$_} == $nb_dirs } keys %files;
+say "\nFiles not common to all directories: ";
+for my $dir (@dirs) {
+ say "$dir: ", join " ", grep { $files{$_} < $nb_dirs } @{$dircontent{$dir}};
+}
diff --git a/challenge-166/laurent-rosenfeld/raku/ch-1.raku b/challenge-166/laurent-rosenfeld/raku/ch-1.raku
new file mode 100644
index 0000000000..b601539ede
--- /dev/null
+++ b/challenge-166/laurent-rosenfeld/raku/ch-1.raku
@@ -0,0 +1,5 @@
+for "words.txt".IO.lines -> $line {
+ next unless 2 <= $line.chars <= 8;
+ next if $line ~~ /<-[a..f olist]>/;
+ say "$_ -> 0x", TR/olist/01157/ with $line;
+}
diff --git a/challenge-166/laurent-rosenfeld/raku/ch-1a.raku b/challenge-166/laurent-rosenfeld/raku/ch-1a.raku
new file mode 100644
index 0000000000..725e100465
--- /dev/null
+++ b/challenge-166/laurent-rosenfeld/raku/ch-1a.raku
@@ -0,0 +1,9 @@
+sub MAIN (Int $limit = 4) {
+ for "words.txt".IO.lines -> $line {
+ next unless 2 <= $line.chars <= 8;
+ next if $line ~~ /<-[a..f olist]>/;
+ my $word = $line;
+ my $dist = +tr/olist/01157/ for $word;
+ say "$line -> 0x", $word if $dist <= $limit
+ }
+}
diff --git a/challenge-166/laurent-rosenfeld/raku/ch-2.raku b/challenge-166/laurent-rosenfeld/raku/ch-2.raku
new file mode 100644
index 0000000000..5dd46cafa5
--- /dev/null
+++ b/challenge-166/laurent-rosenfeld/raku/ch-2.raku
@@ -0,0 +1,11 @@
+my @dirs = map {$_ ~~ /\w+$/}, dir("./rootdir");
+my %dircontent;
+for @dirs -> $dir {
+ %dircontent{$dir} = map {~($_ ~~ /\w+$/)}, dir("./rootdir/$dir");
+}
+say "Content of the dirs: ", %dircontent;
+my $intersection = [∩] values %dircontent;
+say "Files common to all directories: ", $intersection.keys;
+for @dirs -> $dir {
+ say "$dir -> ", grep {$_ ∉ $intersection}, values %dircontent{$dir};
+}