aboutsummaryrefslogtreecommitdiff
path: root/challenge-033
diff options
context:
space:
mode:
authorMohammad S Anwar <Mohammad.Anwar@yahoo.com>2019-11-10 10:36:23 +0000
committerGitHub <noreply@github.com>2019-11-10 10:36:23 +0000
commit3b31bae1fbfb8806cc55cfa2cbb8ff656d425af4 (patch)
treee5f60d69597036b2d0d0e77a222f5e00ab8e36c2 /challenge-033
parentdb5f4dd8cc11b3b8a1c39652381b23ba12e13145 (diff)
parent2c32995ebe9bcfcbf4f31932ea0c5933d0e0ae4f (diff)
downloadperlweeklychallenge-club-3b31bae1fbfb8806cc55cfa2cbb8ff656d425af4.tar.gz
perlweeklychallenge-club-3b31bae1fbfb8806cc55cfa2cbb8ff656d425af4.tar.bz2
perlweeklychallenge-club-3b31bae1fbfb8806cc55cfa2cbb8ff656d425af4.zip
Merge pull request #913 from jaldhar/challenge-033
Challenge 33 by Jaldhar H. Vyas
Diffstat (limited to 'challenge-033')
-rw-r--r--challenge-033/jaldhar-h-vyas/blog.txt1
-rwxr-xr-xchallenge-033/jaldhar-h-vyas/perl5/ch-1.pl28
-rwxr-xr-xchallenge-033/jaldhar-h-vyas/perl5/ch-2.pl14
-rwxr-xr-xchallenge-033/jaldhar-h-vyas/perl6/ch-1.p619
-rwxr-xr-xchallenge-033/jaldhar-h-vyas/perl6/ch-2.p615
5 files changed, 77 insertions, 0 deletions
diff --git a/challenge-033/jaldhar-h-vyas/blog.txt b/challenge-033/jaldhar-h-vyas/blog.txt
new file mode 100644
index 0000000000..a0b3f5e22b
--- /dev/null
+++ b/challenge-033/jaldhar-h-vyas/blog.txt
@@ -0,0 +1 @@
+https://www.braincells.com/perl/2019/11/perl_weekly_challenge_week_33.html
diff --git a/challenge-033/jaldhar-h-vyas/perl5/ch-1.pl b/challenge-033/jaldhar-h-vyas/perl5/ch-1.pl
new file mode 100755
index 0000000000..3766c875b7
--- /dev/null
+++ b/challenge-033/jaldhar-h-vyas/perl5/ch-1.pl
@@ -0,0 +1,28 @@
+#!/usr/bin/perl
+use warnings;
+use strict;
+use 5.010;
+use English qw/ -no_match_vars /;
+
+my @contents;
+if (scalar @ARGV) {
+ for my $file (@ARGV) {
+ open my $fh, '<', $file or die "$OS_ERROR\n";
+ local $INPUT_RECORD_SEPARATOR = undef;
+ push @contents, split //, <$fh>;
+ close $fh;
+ }
+} else {
+ local $INPUT_RECORD_SEPARATOR = undef;
+ push @contents, split //, <STDIN>;
+}
+
+my %totals;
+for my $item (@contents) {
+ $totals{lc $item}++;
+}
+
+for my $total (sort grep / \p{XPosixLower} /msx, keys %totals) {
+ say "$total: $totals{$total}";
+}
+
diff --git a/challenge-033/jaldhar-h-vyas/perl5/ch-2.pl b/challenge-033/jaldhar-h-vyas/perl5/ch-2.pl
new file mode 100755
index 0000000000..2086c9eab5
--- /dev/null
+++ b/challenge-033/jaldhar-h-vyas/perl5/ch-2.pl
@@ -0,0 +1,14 @@
+#!/usr/bin/perl
+use warnings;
+use strict;
+use 5.010;
+
+print ' x|', (join q{}, map { sprintf('% 4s', $_); } 1 .. 11), "\n",
+ '---+', '----' x 11, "\n";
+
+for my $row (1 .. 11) {
+ printf("% 3s|%s\n", $row,
+ (join q{},
+ map { sprintf('% 4s', ($_ < $row) ? q{ } x 4 : $row * $_); } 1 .. 11)
+ );
+}
diff --git a/challenge-033/jaldhar-h-vyas/perl6/ch-1.p6 b/challenge-033/jaldhar-h-vyas/perl6/ch-1.p6
new file mode 100755
index 0000000000..65dfc8f0f6
--- /dev/null
+++ b/challenge-033/jaldhar-h-vyas/perl6/ch-1.p6
@@ -0,0 +1,19 @@
+#!/usr/bin/perl6
+
+sub MAIN(
+ *@files
+) {
+ my %totals;
+
+ if @files.elems {
+ for @files -> $file {
+ $file.IO.comb.map({ %totals{$_.lc}++; });
+ }
+ } else {
+ $*IN.comb.map({ %totals{$_.lc}++; });
+ }
+
+ %totals.keys.grep({ / <lower> / }).sort.map({
+ say "$_: %totals{$_}";
+ });
+}
diff --git a/challenge-033/jaldhar-h-vyas/perl6/ch-2.p6 b/challenge-033/jaldhar-h-vyas/perl6/ch-2.p6
new file mode 100755
index 0000000000..0865d443fc
--- /dev/null
+++ b/challenge-033/jaldhar-h-vyas/perl6/ch-2.p6
@@ -0,0 +1,15 @@
+#!/usr/bin/perl6
+
+constant $N = 11;
+
+say ' x|', (1 .. $N).fmt('% 4s', q{}), "\n", '---+', ('----' x $N);
+
+my @table = (1 .. $N X 1 .. $N).grep({ $_[1] >= $_[0]}).map({ $_[0] * $_[1] });
+
+for (1 .. $N) {
+ printf "% 3s|%s%s\n",
+ $_,
+ q{ } x 4 * ($_ - 1),
+ @table.splice(0, $N - $_ + 1).fmt('% 4s', q{});
+};
+