diff options
| author | Jaldhar H. Vyas <jaldhar@braincells.com> | 2019-11-10 01:52:23 -0500 |
|---|---|---|
| committer | Jaldhar H. Vyas <jaldhar@braincells.com> | 2019-11-10 01:52:23 -0500 |
| commit | 2c32995ebe9bcfcbf4f31932ea0c5933d0e0ae4f (patch) | |
| tree | d47ed08f0bb28a625168f22d79227b2bc1351aec | |
| parent | b827d90735f6fa7501cb37d05f762ff2a7152035 (diff) | |
| download | perlweeklychallenge-club-2c32995ebe9bcfcbf4f31932ea0c5933d0e0ae4f.tar.gz perlweeklychallenge-club-2c32995ebe9bcfcbf4f31932ea0c5933d0e0ae4f.tar.bz2 perlweeklychallenge-club-2c32995ebe9bcfcbf4f31932ea0c5933d0e0ae4f.zip | |
Challenge 33 by Jaldhar H. Vyas
| -rw-r--r-- | challenge-033/jaldhar-h-vyas/blog.txt | 1 | ||||
| -rwxr-xr-x | challenge-033/jaldhar-h-vyas/perl5/ch-1.pl | 28 | ||||
| -rwxr-xr-x | challenge-033/jaldhar-h-vyas/perl5/ch-2.pl | 14 | ||||
| -rwxr-xr-x | challenge-033/jaldhar-h-vyas/perl6/ch-1.p6 | 19 | ||||
| -rwxr-xr-x | challenge-033/jaldhar-h-vyas/perl6/ch-2.p6 | 15 |
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{}); +}; + |
