aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorsouthpawgeek <jen@southpawgeek.com>2020-02-29 11:16:40 -0500
committersouthpawgeek <jen@southpawgeek.com>2020-02-29 11:16:40 -0500
commita13ecc96a8da126bf8ecc897590bf55893f38f86 (patch)
treee8caf7a146496cccba23a1435bfab7a59bf7071a
parent0f6260120be35fc120f9d711790e7094e99fb72e (diff)
parent4a0e7a230f9da4ca47237cf6323ff3fb07757889 (diff)
downloadperlweeklychallenge-club-a13ecc96a8da126bf8ecc897590bf55893f38f86.tar.gz
perlweeklychallenge-club-a13ecc96a8da126bf8ecc897590bf55893f38f86.tar.bz2
perlweeklychallenge-club-a13ecc96a8da126bf8ecc897590bf55893f38f86.zip
merge upstream
-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-045/roger-bell-west/blog.txt1
-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/dave-jacoby/perl/ch-1.pl39
-rwxr-xr-xchallenge-049/duane-powell/perl/ch-1.pl60
-rwxr-xr-xchallenge-049/duane-powell/perl/ch-2.pl189
-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.pl73
-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/luca-ferrari/blog1.txt1
-rw-r--r--challenge-049/luca-ferrari/blog2.txt1
-rw-r--r--challenge-049/luca-ferrari/raku/ch-1.p619
-rw-r--r--challenge-049/luca-ferrari/raku/ch-2.p6155
-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/perl/ch-1.pl11
-rw-r--r--challenge-049/mohammad-anwar/perl/ch-2.pl21
-rw-r--r--challenge-049/mohammad-anwar/raku/ch-1.p69
-rw-r--r--challenge-049/orestis-zekai/python/ch-1.py13
-rw-r--r--challenge-049/orestis-zekai/python/ch-2.py37
-rwxr-xr-xchallenge-049/peter-scott/perl/ch-1.sh2
-rwxr-xr-xchallenge-049/roger-bell-west/perl/ch-1.pl16
-rw-r--r--challenge-049/roger-bell-west/perl/ch-2.pl57
-rwxr-xr-xchallenge-049/roger-bell-west/raku/ch-1.p614
-rw-r--r--challenge-049/roger-bell-west/raku/ch-2.p641
-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.p618
-rw-r--r--challenge-049/simon-proctor/raku/ch-2.p673
-rw-r--r--challenge-049/wanderdoc/perl/ch-1.pl59
-rw-r--r--challenge-049/wanderdoc/perl/ch-2.pl164
-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-045.json288
-rw-r--r--stats/pwc-challenge-046.json462
-rw-r--r--stats/pwc-challenge-048.json683
-rw-r--r--stats/pwc-current.json525
-rw-r--r--stats/pwc-language-breakdown-summary.json78
-rw-r--r--stats/pwc-language-breakdown.json707
-rw-r--r--stats/pwc-leaders.json578
-rw-r--r--stats/pwc-summary-1-30.json46
-rw-r--r--stats/pwc-summary-121-150.json50
-rw-r--r--stats/pwc-summary-151-180.json48
-rw-r--r--stats/pwc-summary-31-60.json134
-rw-r--r--stats/pwc-summary-61-90.json68
-rw-r--r--stats/pwc-summary-91-120.json70
-rw-r--r--stats/pwc-summary.json392
73 files changed, 5047 insertions, 2174 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-045/roger-bell-west/blog.txt b/challenge-045/roger-bell-west/blog.txt
new file mode 100644
index 0000000000..f134a2e023
--- /dev/null
+++ b/challenge-045/roger-bell-west/blog.txt
@@ -0,0 +1 @@
+https://blog.firedrake.org/archive/2020/02/Perl_Weekly_Challenge_45__bad_codes_and_quines.html
diff --git a/challenge-046/roger-bell-west/blog.txt b/challenge-046/roger-bell-west/blog.txt
new file mode 100644
index 0000000000..9c28a83383
--- /dev/null
+++ b/challenge-046/roger-bell-west/blog.txt
@@ -0,0 +1 @@
+https://blog.firedrake.org/archive/2020/02/Perl_Weekly_Challenge_46__corrupt_messages_and_hotel_rooms.html
diff --git a/challenge-047/arne-sommer/raku/lib/Number/Roman.rakumod b/challenge-047/arne-sommer/raku/lib/Number/Roman.rakumod
new file mode 100644
index 0000000000..1196448d6a
--- /dev/null
+++ b/challenge-047/arne-sommer/raku/lib/Number/Roman.rakumod
@@ -0,0 +1,85 @@
+use v6;
+use MONKEY-TYPING;
+
+unit module Number::Roman;
+
+our sub to-roman (Int $number is copy) is export(:to)
+{
+ my $string = "";
+
+ while $number >= 1000 { $string ~= "M"; $number -= 1000; }
+ if $number >= 900 { $string ~= "CM"; $number -= 900; }
+ if $number >= 500 { $string ~= "D"; $number -= 500; }
+ if $number >= 400 { $string ~= "CD"; $number -= 400; }
+ while $number >= 100 { $string ~= "C"; $number -= 100; }
+ if $number >= 90 { $string ~= "XC"; $number -= 90; }
+ if $number >= 50 { $string ~= "L"; $number -= 50; }
+ if $number >= 40 { $string ~= "XL"; $number -= 40; }
+ while $number >= 10 { $string ~= "X"; $number -= 10; }
+ if $number >= 9 { $string ~= "IX"; $number -= 9; }
+ if $number >= 5 { $string ~= "V"; $number -= 5; }
+ if $number >= 4 { $string ~= "IV"; $number -= 4; }
+ while $number >= 1 { $string ~= "I"; $number -= 1; }
+
+ return $string;
+}
+
+my %value = (I => 1, V => 5, X => 10, L => 50, C => 100, D => 500, M => 1000);
+
+my Set $valid-roman = %value.keys.Set;
+
+my $current-value = Inf;
+
+our sub from-roman (Str $roman) is export(:from)
+{
+ my @digits = $roman.comb;
+
+ die "Non-Roman digit $_ detected." unless $valid-roman{$_} for @digits;
+
+ my $number = 0;
+
+ while @digits
+ {
+ my $current = @digits.shift;
+
+ if @digits.elems
+ {
+ if %value{@digits[0]} > %value{$current}
+ {
+ $number += %value{@digits.shift} - %value{$current};
+ next;
+ }
+ }
+ $number += %value{$current};
+ }
+
+ return to-roman($number) eq $roman
+ ?? $number
+ !! die "Not a valid Roman Number: $roman";
+}
+
+augment class Int
+{
+ method roman
+ {
+ return to-roman(self);
+ }
+
+ multi method base ("r")
+ {
+ return self.roman;
+ }
+}
+
+augment class Str
+{
+ method from-roman
+ {
+ return from-roman(self);
+ }
+
+ multi method parse-base ("r")
+ {
+ return self.from-roman;
+ }
+}
diff --git a/challenge-047/arne-sommer/raku/lib/Number/Roman/OO.rakumod b/challenge-047/arne-sommer/raku/lib/Number/Roman/OO.rakumod
new file mode 100644
index 0000000000..a8bcda0733
--- /dev/null
+++ b/challenge-047/arne-sommer/raku/lib/Number/Roman/OO.rakumod
@@ -0,0 +1,67 @@
+use v6;
+
+use Number::Roman :to, :from;
+
+unit class Number::Roman::OO;
+
+has Int $.value;
+
+multi method new (Str $string) { self.bless(value => from-roman($string)) }
+multi method new($value) { self.bless(:$value) }
+
+multi method add (Number::Roman::OO:D $obj) { return self.new(self.value + $obj.Int) }
+multi method add (Int $int) { return self.new(self.value - $int) }
+
+multi method sub (Number::Roman::OO:D $obj) { return self.new(self.value + $obj.Int) }
+multi method sub (Int $int) { return self.new(self.value - $int) }
+
+multi method mul (Number::Roman::OO:D $obj) { return self.new(self.value * $obj.Int) }
+multi method mul (Int $int) { return self.new(self.value * $int) }
+
+multi method div (Number::Roman::OO:D $obj) { return self.new(Int(self.value / $obj.Int)) }
+multi method div (Int $int) { return self.new(Int(self.value / $int)) }
+
+method Str { to-roman(self.value) }
+method gist { to-roman(self.value) }
+method Int { self.value }
+method Real { self.value }
+</