aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRyan Thompson <i@ry.ca>2020-03-01 04:07:41 -0600
committerRyan Thompson <i@ry.ca>2020-03-01 04:07:41 -0600
commitea66028356d5cd528de341f00b30d1f84840c127 (patch)
tree3a8cdcba2cb0c50af235def97eca186c5533df81
parent712204bb937f97cc022c5adb9852d22e07a245f8 (diff)
parentfecba96965f6f1d10e7ad8b3628c6891ab1872af (diff)
downloadperlweeklychallenge-club-ea66028356d5cd528de341f00b30d1f84840c127.tar.gz
perlweeklychallenge-club-ea66028356d5cd528de341f00b30d1f84840c127.tar.bz2
perlweeklychallenge-club-ea66028356d5cd528de341f00b30d1f84840c127.zip
Merge remote-tracking branch 'upstream/master' into rjt_049
-rw-r--r--README.md4
-rw-r--r--challenge-034/yet-ebreo/perl5/ch-1.pl28
-rw-r--r--challenge-034/yet-ebreo/perl5/ch-2.pl41
-rw-r--r--challenge-035/yet-ebreo/perl5/ch-1.pl77
-rw-r--r--challenge-035/yet-ebreo/perl5/ch-2.pl68
-rw-r--r--challenge-036/yet-ebreo/perl5/ch-1.pl20
-rw-r--r--challenge-036/yet-ebreo/perl5/ch-2.pl68
-rw-r--r--challenge-038/jaldhar-h-vyas/blog.txt1
-rwxr-xr-xchallenge-038/jaldhar-h-vyas/perl/ch-1.pl42
-rwxr-xr-xchallenge-038/jaldhar-h-vyas/perl/ch-2.pl117
-rwxr-xr-xchallenge-038/jaldhar-h-vyas/raku/ch-1.p656
-rwxr-xr-xchallenge-038/jaldhar-h-vyas/raku/ch-2.p651
-rw-r--r--challenge-046/roger-bell-west/blog.txt1
-rw-r--r--challenge-047/arne-sommer/raku/lib/Number/Roman.rakumod85
-rw-r--r--challenge-047/arne-sommer/raku/lib/Number/Roman/OO.rakumod67
-rw-r--r--challenge-048/jitu-keshwani/README1
-rwxr-xr-xchallenge-048/jitu-keshwani/perl/ch-1.pl87
-rwxr-xr-xchallenge-048/jitu-keshwani/perl/ch-2.pl37
-rw-r--r--challenge-049/cheok-yin-fung/perl/ch-1.pl52
-rw-r--r--challenge-049/dave-jacoby/perl/ch-1.pl39
-rw-r--r--challenge-049/dave-jacoby/perl/ch-2.pl140
-rwxr-xr-xchallenge-049/duane-powell/perl/ch-1.pl60
-rwxr-xr-xchallenge-049/duane-powell/perl/ch-2.pl189
-rw-r--r--challenge-049/e-choroba/blog.txt1
-rwxr-xr-xchallenge-049/e-choroba/perl/ch-1.pl14
-rwxr-xr-xchallenge-049/e-choroba/perl/ch-1a.pl28
-rwxr-xr-xchallenge-049/e-choroba/perl/ch-2.pl71
-rwxr-xr-xchallenge-049/e-choroba/perl/ch-2b.pl134
-rw-r--r--challenge-049/javier-luque/blog.txt1
-rw-r--r--challenge-049/javier-luque/perl/ch-1.pl20
-rw-r--r--challenge-049/javier-luque/perl/ch-2.pl197
-rw-r--r--challenge-049/javier-luque/raku/ch-1.p613
-rw-r--r--challenge-049/javier-luque/raku/ch-2.p6116
-rw-r--r--challenge-049/kevin-colyer/raku/ch-1.p622
-rw-r--r--challenge-049/kevin-colyer/raku/ch-2.p6105
-rw-r--r--challenge-049/laurent-rosenfeld/blog.txt1
-rw-r--r--challenge-049/laurent-rosenfeld/perl/ch-1.pl14
-rw-r--r--challenge-049/laurent-rosenfeld/perl/ch-2.pl39
-rw-r--r--challenge-049/laurent-rosenfeld/raku/ch-1.p65
-rw-r--r--challenge-049/laurent-rosenfeld/raku/ch-2.p634
-rw-r--r--challenge-049/mark-anderson/raku/ch-1.p68
-rw-r--r--challenge-049/mark-anderson/raku/ch-2.p683
-rw-r--r--challenge-049/markus-holzer/raku/ch-1.p64
-rw-r--r--challenge-049/mohammad-anwar/blog.txt1
-rw-r--r--challenge-049/mohammad-anwar/raku/ch-1.p64
-rw-r--r--challenge-049/orestis-zekai/python/ch-1.py13
-rw-r--r--challenge-049/orestis-zekai/python/ch-2.py37
-rw-r--r--challenge-049/saiftynet/perl/ch-1.pl59
-rw-r--r--challenge-049/saiftynet/perl/ch-2.pl138
-rw-r--r--challenge-049/simon-proctor/blog.txt1
-rw-r--r--challenge-049/simon-proctor/raku/ch-1.p610
-rw-r--r--challenge-049/southpawgeek/ch-1.pl19
-rw-r--r--challenge-049/steven-wilson/perl/ch-1.pl33
-rwxr-xr-xchallenge-049/user-person/perl/ch-1.sh18
-rwxr-xr-xchallenge-049/user-person/perl/ch-2.pl131
-rwxr-xr-xchallenge-049/user-person/python/ch-1.py24
-rwxr-xr-xchallenge-049/user-person/python/ch-2.py102
-rwxr-xr-xchallenge-049/xkr47/raku/ch-1.p69
-rw-r--r--challenge-049/xkr47/rust/Cargo.toml12
-rw-r--r--challenge-049/xkr47/rust/ch-1.rs14
-rw-r--r--challenge-049/yet-ebreo/perl/ch-1.pl21
-rw-r--r--challenge-049/yet-ebreo/perl/ch-2.pl80
-rw-r--r--members.json1
-rw-r--r--stats/pwc-challenge-034.json197
-rw-r--r--stats/pwc-challenge-035.json213
-rw-r--r--stats/pwc-challenge-036.json205
-rw-r--r--stats/pwc-challenge-038.json363
-rw-r--r--stats/pwc-challenge-046.json462
-rw-r--r--stats/pwc-challenge-048.json545
-rw-r--r--stats/pwc-current.json359
-rw-r--r--stats/pwc-language-breakdown-summary.json76
-rw-r--r--stats/pwc-language-breakdown.json754
-rw-r--r--stats/pwc-leaders.json880
-rw-r--r--stats/pwc-summary-1-30.json40
-rw-r--r--stats/pwc-summary-121-150.json72
-rw-r--r--stats/pwc-summary-151-180.json42
-rw-r--r--stats/pwc-summary-31-60.json126
-rw-r--r--stats/pwc-summary-61-90.json140
-rw-r--r--stats/pwc-summary-91-120.json116
-rw-r--r--stats/pwc-summary.json400
80 files changed, 5632 insertions, 2326 deletions
diff --git a/README.md b/README.md
index 5c7bc148aa..6f7cd72c1f 100644
--- a/README.md
+++ b/README.md
@@ -2,6 +2,10 @@
This is the central repository for the members of [**Perl Weekly Challenge**](https://perlweeklychallenge.org). The members can submit the solution to the challenge each week under version control.
+## EZPWC - Easy Perl Weekly Challenges Script
+
+**Saif Ahmed**, respected member of **Team PWC**, created the tool **[EZPWC](https://github.com/saiftynet/EZPWC)** to help you with contributing to the weekly challenge. We highly recommend you to give it a try. If you have any questions/suggestions, then please raise an issue against the tool.
+
## How to contribute?
Just submit Pull Request with your solutions.
diff --git a/challenge-034/yet-ebreo/perl5/ch-1.pl b/challenge-034/yet-ebreo/perl5/ch-1.pl
new file mode 100644
index 0000000000..b9aabf6867
--- /dev/null
+++ b/challenge-034/yet-ebreo/perl5/ch-1.pl
@@ -0,0 +1,28 @@
+#!/usr/bin/perl
+
+use strict;
+use warnings;
+use feature 'say';
+
+my @array = qw(a quick brown fox jumps over the lazy dog);
+
+#Using index
+say $array[4];
+
+#Using multiple indices
+my @sliced_array = @array[2,3];
+say @sliced_array;
+
+#Using range
+@sliced_array = @array[2..6];
+
+say @sliced_array;
+
+my $n = 0;
+my %hash = map { $_ => $n++ } @array;
+
+#Using one key
+say $hash{'jumps'};
+
+#Using array as keys
+say @hash{qw(jumps dog a)}; \ No newline at end of file
diff --git a/challenge-034/yet-ebreo/perl5/ch-2.pl b/challenge-034/yet-ebreo/perl5/ch-2.pl
new file mode 100644
index 0000000000..b0c253f846
--- /dev/null
+++ b/challenge-034/yet-ebreo/perl5/ch-2.pl
@@ -0,0 +1,41 @@
+#!/usr/bin/perl
+
+use strict;
+use warnings;
+use feature 'say';
+
+my %table = (
+ add => \&add,
+ subtract => \&subtract,
+ multiply => \&multiply,
+ divide => \&divide
+);
+
+sub divide {
+ my ($m,$n) = @_;
+ say "Error: Divide by 0" if !$n;
+
+ return $m/$n;
+}
+
+sub add {
+ my ($m,$n) = @_;
+ return $m+$n;
+}
+
+sub subtract {
+ my ($m,$n) = @_;
+ return $m-$n;
+}
+
+sub multiply {
+ my ($m,$n) = @_;
+ return $m*$n;
+}
+
+my $commands = "add multiply subtract divide";
+my @operands = (43,6);
+for my $cmd ($commands=~/\w+/g) {
+ say "[$cmd]";
+ say $table{$cmd}->(@operands);
+} \ No newline at end of file
diff --git a/challenge-035/yet-ebreo/perl5/ch-1.pl b/challenge-035/yet-ebreo/perl5/ch-1.pl
new file mode 100644
index 0000000000..4eaa827c8a
--- /dev/null
+++ b/challenge-035/yet-ebreo/perl5/ch-1.pl
@@ -0,0 +1,77 @@
+#!/usr/bin/perl
+
+use strict;
+use warnings;
+use feature 'say';
+
+# Morse Code Char Set
+# dot: 1
+# dash: 111
+# intra-character gap: 0
+# character gap: 000
+# word gap: 0000000
+
+my %m_encode = (
+ 0=>489335,
+ 1=>96119,
+ 2=>22391,
+ 3=>5495,
+ 4=>1367,
+ 5=>341,
+ 6=>1877,
+ 7=>7637,
+ 8=>30581,
+ 9=>122333,
+ A=>23,
+ B=>469,
+ C=>1885,
+ D=>117,
+ E=>1,
+ F=>349,
+ G=>477,
+ H=>85,
+ I=>5,
+ J=>6007,
+ K=>471,
+ L=>373,
+ M=>119,
+ N=>29,
+ O=>1911,
+ P=>1501,
+ Q=>7639,
+ R=>93,
+ S=>21,
+ T=>7,
+ U=>87,
+ V=>343,
+ W=>375,
+ X=>1879,
+ Y=>7543,
+ Z=>1909
+);
+
+my $string_to_encode = $ARGV[0] || "A QUICK BROWN FOX JUMPS OVER THE LAZY DOG";
+
+sub encode {
+ my $string = uc pop;
+ return $string =~
+ #Insert # in between letters using \b
+ s/\B/#/gr =~
+ #Replace space which separate words, with @
+ s/ /@/gr =~
+ #Replace alphanumeric + _ matches with the morsecode from hash table
+ s/\w/sprintf "%b", $m_encode{$&}/gre =~
+ #Replace # with the assigned character gap
+ s/#/000/gr =~
+ #Replace @ with the assigned word gap
+ s/@/0000000/gr ;
+}
+
+my $encoded_string = encode($string_to_encode);
+
+say "Encoded Morse Code: ".$encoded_string;
+
+=begin
+perl .\ch-1.pl "just another perl hacker"
+Encoded Morse Code: 101110111011100010101110001010100011100000001011100011101000111011101110001110001010101000100010111010000000101110111010001000101110100010111010100000001010101000101110001110101110100011101011100010001011101
+=cut \ No newline at end of file
diff --git a/challenge-035/yet-ebreo/perl5/ch-2.pl b/challenge-035/yet-ebreo/perl5/ch-2.pl
new file mode 100644
index 0000000000..d8f3f39e57
--- /dev/null
+++ b/challenge-035/yet-ebreo/perl5/ch-2.pl
@@ -0,0 +1,68 @@
+#!/usr/bin/perl
+
+use strict;
+use warnings;
+use feature 'say';
+
+my %m_decode = (
+ "489335" =>"0",
+ "96119" =>"1",
+ "22391" =>"2",
+ "5495" =>"3",
+ "1367" =>"4",
+ "341" =>"5",
+ "1877" =>"6",
+ "7637" =>"7",
+ "30581" =>"8",
+ "122333" =>"9",
+ "23" =>"A",
+ "469" =>"B",
+ "1885" =>"C",
+ "117" =>"D",
+ "1" =>"E",
+ "349" =>"F",
+ "477" =>"G",
+ "85" =>"H",
+ "5" =>"I",
+ "6007" =>"J",
+ "471" =>"K",
+ "373" =>"L",
+ "119" =>"M",
+ "29" =>"N",
+ "1911" =>"O",
+ "1501" =>"P",
+ "7639" =>"Q",
+ "93" =>"R",
+ "21" =>"S",
+ "7" =>"T",
+ "87" =>"U",
+ "343" =>"V",
+ "375" =>"W",
+ "1879" =>"X",
+ "7543" =>"Y",
+ "1909" =>"Z"
+);
+
+my $string_to_decode = $ARGV[0] || "10111000000011101110101110001010111000101000111010111010001110101110000000111010101000101110100011101110111000101110111000111010000000101011101000111011101110001110101011100000001011101110111000101011100011101110001011101110100010101000000011101110111000101010111000100010111010000000111000101010100010000000101110101000101110001110111010100011101011101110000000111010100011101110111000111011101";
+
+sub decode {
+ my $string = pop =~
+ #Replace the assigned word gap with @
+ s/0000000/@/gr =~
+ #Replace the assigned char gap with #
+ s/000/#/gr =~
+ #Replace morse code with equivalent char from hash
+ s/[01]+/$m_decode{oct "b$&"}/gre =~
+ #Replace @ with space
+ s/@/ /gr =~
+ #Remove #'s
+ s/#//gr;
+ return $string
+}
+
+say "Decoded String: ".decode($string_to_decode);
+
+=begin
+perl .\ch-2.pl 101110111011100010101110001010100011100000001011100011101000111011101110001110001010101000100010111010000000101110111010001000101110100010111010100000001010101000101110001110101110100011101011100010001011101
+Decoded String: JUST ANOTHER PERL HACKER
+=cut \ No newline at end of file
diff --git a/challenge-036/yet-ebreo/perl5/ch-1.pl b/challenge-036/yet-ebreo/perl5/ch-1.pl
new file mode 100644
index 0000000000..94425694a1
--- /dev/null
+++ b/challenge-036/yet-ebreo/perl5/ch-1.pl
@@ -0,0 +1,20 @@
+#!/usr/bin/perl
+
+use strict;
+use warnings;
+use feature 'say';
+
+if (@ARGV != 1) {
+ say "Usage:\n\tperl ch-1.pl <VIN>\n\n";
+} else {
+ my $vin = $ARGV[0];
+ if ($vin =~ /[OIQ]/i) {
+ say "Invalid VIN";
+ } else {
+ if ($vin =~ /^[A-Z0-9]{17}$/i) {
+ say "VIN is valid";
+ } else {
+ say "Invalid VIN";
+ }
+ }
+} \ No newline at end of file
diff --git a/challenge-036/yet-ebreo/perl5/ch-2.pl b/challenge-036/yet-ebreo/perl5/ch-2.pl
new file mode 100644
index 0000000000..0f207404be
--- /dev/null
+++ b/challenge-036/yet-ebreo/perl5/ch-2.pl
@@ -0,0 +1,68 @@
+#!/usr/bin/perl
+
+use strict;
+use warnings;
+use feature 'say';
+
+my %boxes = (
+ R => {w => 1, v => 1},
+ B => {w => 1, v => 2},
+ G => {w => 2, v => 2},
+ Y => {w => 12, v => 4},
+ P => {w => 4, v => 10}
+);
+
+if (@ARGV < 2) {
+ die "Usage:\n\tperl ch-2.pl <max_item> <max_weight>\n\n";
+}
+my $max_item = $ARGV[0];
+my $max_weight = $ARGV[1];
+
+my @g_keys = keys %boxes;
+my @g_wt = map { $boxes{$_}{w} } @g_keys;
+my @g_val = map { $boxes{$_}{v} } @g_keys;
+my $max = 0;
+my $mask;
+
+for my $bitmask (1..2**@g_keys) {
+
+ my ($c_weight,$c_value,$c_item_cnt) = (0) x 3;
+
+ for my $p (0..~-@g_keys) {
+ if ($bitmask & 1<<$p) {
+
+ if ((++$c_item_cnt <= $max_item) && ($c_weight + $boxes{$g_keys[$p]}{w} <= $max_weight)) {
+ $c_value += $boxes{$g_keys[$p]}{v};
+ $c_weight += $boxes{$g_keys[$p]}{w};
+ }
+ }
+ }
+ if ($c_value > $max) {
+ $max = $c_value;
+ $mask = $bitmask;
+ }
+}
+
+say "Color Value Weight";
+map { ($mask & 1 << $_) && printf ("$g_keys[$_] %02d %02d\n", $boxes{$g_keys[$_]}{v}, $boxes{$g_keys[$_]}{w}) } (0..~-@g_keys);
+say "Max Value: $max";
+=begin
+perl .\ch-2.pl 2 15
+Color Value Weight
+B 02 01
+P 10 04
+Max Value: 12
+
+perl .\ch-2.pl 5 15
+Color Value Weight
+G 02 02
+B 02 01
+P 10 04
+R 01 01
+Max Value: 15
+
+perl .\ch-2.pl 1 15
+Color Value Weight
+P 10 04
+Max Value: 10
+=cut \ No newline at end of file
diff --git a/challenge-038/jaldhar-h-vyas/blog.txt b/challenge-038/jaldhar-h-vyas/blog.txt
new file mode 100644
index 0000000000..8885c6d42b
--- /dev/null
+++ b/challenge-038/jaldhar-h-vyas/blog.txt
@@ -0,0 +1 @@
+https://www.braincells.com/perl/2020/02/perl_weekly_challenge_week_38.html
diff --git a/challenge-038/jaldhar-h-vyas/perl/ch-1.pl b/challenge-038/jaldhar-h-vyas/perl/ch-1.pl
new file mode 100755
index 0000000000..dd9ebd39b1
--- /dev/null
+++ b/challenge-038/jaldhar-h-vyas/perl/ch-1.pl
@@ -0,0 +1,42 @@
+#!/usr/bin/perl
+use warnings;
+use strict;
+use 5.010;
+
+sub isLeap {
+ my ($year) = @_;
+ return $year % 4 == 0 && ($year % 100 != 0 || $year % 400 == 0);
+}
+
+sub isValidDate {
+ my ($year, $month, $day) = @_;
+
+ if ($month == 2 && $day > (isLeap($year) ? 29 : 28)) {
+ return undef;
+ }
+
+ if ((grep { $month == $_ } ( 4, 6, 9, 11 )) && $day > 30) {
+ return undef;
+ }
+
+ return 1;
+}
+
+my $input = shift // q{};
+
+if ($input =~ m{
+ \A
+ (?<century> [12])
+ (?<year> [0-9]{2})
+ (?<month> (0[1-9]) | (1[0-2]) )
+ (?<day> (0[1-9]) | ([1-2][0-9]) | (3[01]))
+ \z
+}gmx) {
+ my $year = (($+{century} == 1) ? 20 : 19) . $+{year};
+ if (isValidDate($year, $+{month}, $+{day})) {
+ say join q{-}, ($year, $+{month}, $+{day});
+ exit;
+ }
+}
+
+say 'Invalid date.'; \ No newline at end of file
diff --git a/challenge-038/jaldhar-h-vyas/perl/ch-2.pl b/challenge-038/jaldhar-h-vyas/perl/ch-2.pl
new file mode 100755
index 0000000000..4710c7b080
--- /dev/null
+++ b/challenge-038/jaldhar-h-vyas/perl/ch-2.pl
@@ -0,0 +1,117 @@
+#!/usr/bin/perl
+use warnings;
+use strict;
+use 5.010;
+use English qw/ -no_match_vars /;
+
+sub combinations {
+ my @list = @{$_[0]};
+ my $length = $_[1];
+
+ if ($length <= 1) {
+ return map [$_], @list;
+ }
+
+ my @combos;
+
+ for (my $i = 0; $i + $length <= scalar @list; $i++) {
+ my $val = $list[$i];
+ my @rest = @list[$i + 1 .. $#list];
+ for my $c (combinations(\@rest, $length - 1)) {
+ push @combos, [$val, @{$c}] ;
+ }
+ }
+
+ return @combos;