diff options
| author | Mohammad S Anwar <mohammad.anwar@yahoo.com> | 2019-11-07 11:41:15 +0000 |
|---|---|---|
| committer | Mohammad S Anwar <mohammad.anwar@yahoo.com> | 2019-11-07 11:41:15 +0000 |
| commit | 4b0d246b08356b7a970233709adf20146f63c27e (patch) | |
| tree | be11ba530ca60e1f04e15d4c06f50576f093086f /challenge-033 | |
| parent | defd52225d351bb24dab9dee510336733f9762e0 (diff) | |
| download | perlweeklychallenge-club-4b0d246b08356b7a970233709adf20146f63c27e.tar.gz perlweeklychallenge-club-4b0d246b08356b7a970233709adf20146f63c27e.tar.bz2 perlweeklychallenge-club-4b0d246b08356b7a970233709adf20146f63c27e.zip | |
- Added solutions by Laurent Rosenfeld.
Diffstat (limited to 'challenge-033')
| -rw-r--r-- | challenge-033/laurent-rosenfeld/blog.txt | 1 | ||||
| -rw-r--r-- | challenge-033/laurent-rosenfeld/perl5/ch-1.pl | 17 | ||||
| -rw-r--r-- | challenge-033/laurent-rosenfeld/perl5/ch-2.pl | 21 | ||||
| -rw-r--r-- | challenge-033/laurent-rosenfeld/perl6/ch-1.p6 | 6 | ||||
| -rw-r--r-- | challenge-033/laurent-rosenfeld/perl6/ch-2.p6 | 18 |
5 files changed, 63 insertions, 0 deletions
diff --git a/challenge-033/laurent-rosenfeld/blog.txt b/challenge-033/laurent-rosenfeld/blog.txt new file mode 100644 index 0000000000..7ccfd86c07 --- /dev/null +++ b/challenge-033/laurent-rosenfeld/blog.txt @@ -0,0 +1 @@ +http://blogs.perl.org/users/laurent_r/2019/11/perl-weekly-challenge-33-count-letters-and-multiplication-tables.html diff --git a/challenge-033/laurent-rosenfeld/perl5/ch-1.pl b/challenge-033/laurent-rosenfeld/perl5/ch-1.pl new file mode 100644 index 0000000000..559e372a4b --- /dev/null +++ b/challenge-033/laurent-rosenfeld/perl5/ch-1.pl @@ -0,0 +1,17 @@ +#!/usr/bin/perl +use strict; +use warnings; +use feature qw/say/; + +my %histo; + +while (<>) { + chomp; + my $line = lc; + for my $letter (split //, $line) { + $histo{$letter}++ if $letter =~ /[a-z]/; + } +} +for my $key ("a".."z") { + say "$key: ", $histo{$key} // 0; +} diff --git a/challenge-033/laurent-rosenfeld/perl5/ch-2.pl b/challenge-033/laurent-rosenfeld/perl5/ch-2.pl new file mode 100644 index 0000000000..c9dac9d782 --- /dev/null +++ b/challenge-033/laurent-rosenfeld/perl5/ch-2.pl @@ -0,0 +1,21 @@ +#!/usr/bin/perl +use strict; +use warnings; +use feature 'say'; + +sub print_table { + my $max = shift; + # Print header + printf "%2s |", "x"; + printf "%4d", $_ for 1..$max; + say "\n---|", "-" x (4 * $max); + # Print table lines + for my $i (1..$max) { + printf "%2d |%s", $i, ' ' x (4 * ($i - 1)); + for my $j ($i..$max) { + printf "%4d", $i * $j; + } + say ""; + } +} +print_table shift//11; diff --git a/challenge-033/laurent-rosenfeld/perl6/ch-1.p6 b/challenge-033/laurent-rosenfeld/perl6/ch-1.p6 new file mode 100644 index 0000000000..5b1b2f2d3c --- /dev/null +++ b/challenge-033/laurent-rosenfeld/perl6/ch-1.p6 @@ -0,0 +1,6 @@ +use v6; + +sub MAIN (*@files) { + my $histo = (map {.IO.combĀ».lc}, @files).Bag; + say "$_ : ", $histo{$_} for 'a'..'z'; +} diff --git a/challenge-033/laurent-rosenfeld/perl6/ch-2.p6 b/challenge-033/laurent-rosenfeld/perl6/ch-2.p6 new file mode 100644 index 0000000000..7edd6ba1db --- /dev/null +++ b/challenge-033/laurent-rosenfeld/perl6/ch-2.p6 @@ -0,0 +1,18 @@ +use v6; +sub MAIN (UInt $max = 11) { + print-table($max); +} +sub print-table ($max) { + # Print header + printf "%2s |", "x"; + printf "%4d", $_ for 1..$max; + say "\n---|", "-" x 4 * ($max); + # Print table lines + for 1..$max -> $i { + printf "%2d |%s", $i, ' ' x 4 * ($i - 1); + for $i..$max -> $j { + printf "%4d", $i * $j; + } + say ""; + } +} |
