aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMohammad S Anwar <Mohammad.Anwar@yahoo.com>2021-07-20 14:07:20 +0100
committerGitHub <noreply@github.com>2021-07-20 14:07:20 +0100
commita637d26ec32ca8e593ca9f7b1e694bf5a0e77a01 (patch)
tree1d9aa5a3d6b7ca5817617f11eec2e4dba8fb3758
parent13e5315734ecdb5c9cf8ccefde074a9cff855ac7 (diff)
parent14992ebe13aefb15deab8ce9f2c48748f70dbf61 (diff)
downloadperlweeklychallenge-club-a637d26ec32ca8e593ca9f7b1e694bf5a0e77a01.tar.gz
perlweeklychallenge-club-a637d26ec32ca8e593ca9f7b1e694bf5a0e77a01.tar.bz2
perlweeklychallenge-club-a637d26ec32ca8e593ca9f7b1e694bf5a0e77a01.zip
Merge pull request #4569 from wlmb/challenges
Challenges
-rwxr-xr-xchallenge-121/wlmb/perl/ch-2-helper.pl4
-rwxr-xr-xchallenge-121/wlmb/perl/ch-2.pl4
-rwxr-xr-xchallenge-121/wlmb/perl/ch-2a.pl4
-rwxr-xr-xchallenge-121/wlmb/perl/ch-2b.pl4
-rw-r--r--challenge-122/wlmb/blog.txt1
-rwxr-xr-xchallenge-122/wlmb/perl/ch-1.pl17
-rwxr-xr-xchallenge-122/wlmb/perl/ch-2.pl24
7 files changed, 50 insertions, 8 deletions
diff --git a/challenge-121/wlmb/perl/ch-2-helper.pl b/challenge-121/wlmb/perl/ch-2-helper.pl
index 699d053b81..167f7d350a 100755
--- a/challenge-121/wlmb/perl/ch-2-helper.pl
+++ b/challenge-121/wlmb/perl/ch-2-helper.pl
@@ -1,8 +1,8 @@
#!/usr/bin/env perl
# Perl weekly challenge 121
-# Task 2: The travelling salesman. Auxiliary program
+# Task 2: The traveling salesman. Auxiliary program
#
-# See https://wlmb.github.io/2021/07/12/PWC121/#task-2-the-travelling-salesman
+# See https://wlmb.github.io/2021/07/12/PWC121/#task-2-the-traveling-salesman
use strict;
use warnings;
use v5.12;
diff --git a/challenge-121/wlmb/perl/ch-2.pl b/challenge-121/wlmb/perl/ch-2.pl
index 625227ef9d..9cfa4714d3 100755
--- a/challenge-121/wlmb/perl/ch-2.pl
+++ b/challenge-121/wlmb/perl/ch-2.pl
@@ -1,8 +1,8 @@
#!/usr/bin/env perl
# Perl weekly challenge 121
-# Task 2: The travelling salesman
+# Task 2: The traveling salesman
#
-# See https://wlmb.github.io/2021/07/12/PWC121/#task-2-the-travelling-salesman
+# See https://wlmb.github.io/2021/07/12/PWC121/#task-2-the-traveling-salesman
use strict;
use warnings;
use v5.12;
diff --git a/challenge-121/wlmb/perl/ch-2a.pl b/challenge-121/wlmb/perl/ch-2a.pl
index 26013d3c32..3b083e341b 100755
--- a/challenge-121/wlmb/perl/ch-2a.pl
+++ b/challenge-121/wlmb/perl/ch-2a.pl
@@ -1,8 +1,8 @@
#!/usr/bin/env perl
# Perl weekly challenge 121
-# Task 2: The travelling salesman. Simulated Annealing
+# Task 2: The traveling salesman. Simulated Annealing
#
-# See https://wlmb.github.io/2021/07/12/PWC121/#task-2-the-travelling-salesman
+# See https://wlmb.github.io/2021/07/12/PWC121/#task-2-the-traveling-salesman
use strict;
use warnings;
use v5.12;
diff --git a/challenge-121/wlmb/perl/ch-2b.pl b/challenge-121/wlmb/perl/ch-2b.pl
index caa3647fcc..dccc072066 100755
--- a/challenge-121/wlmb/perl/ch-2b.pl
+++ b/challenge-121/wlmb/perl/ch-2b.pl
@@ -1,8 +1,8 @@
#!/usr/bin/env perl
# Perl weekly challenge 121
-# Task 2: The travelling salesman. Simulated Annealing. Obeying triangle inequality.
+# Task 2: The traveling salesman. Simulated Annealing. Obeying triangle inequality.
#
-# See https://wlmb.github.io/2021/07/12/PWC121/#task-2-the-travelling-salesman
+# See https://wlmb.github.io/2021/07/12/PWC121/#task-2-the-traveling-salesman
use strict;
use warnings;
use v5.12;
diff --git a/challenge-122/wlmb/blog.txt b/challenge-122/wlmb/blog.txt
new file mode 100644
index 0000000000..a5b5fc542e
--- /dev/null
+++ b/challenge-122/wlmb/blog.txt
@@ -0,0 +1 @@
+https://wlmb.github.io/2021/07/19/PWC122/
diff --git a/challenge-122/wlmb/perl/ch-1.pl b/challenge-122/wlmb/perl/ch-1.pl
new file mode 100755
index 0000000000..7c00de90a1
--- /dev/null
+++ b/challenge-122/wlmb/perl/ch-1.pl
@@ -0,0 +1,17 @@
+#!/usr/bin/env perl
+# Perl weekly challenge 122
+# Task 1: Average of stream
+#
+# See https://wlmb.github.io/2021/07/19/PWC122/#task-1-average-of-stream
+use strict;
+use warnings;
+use v5.12;
+my $counter=0; # item counter
+my $total=0; # running total
+while(<>){
+ chomp;
+ ++$counter;
+ $total += $_;
+ my $average=$total/$counter;
+ say "Input: $_ Output: $average";
+}
diff --git a/challenge-122/wlmb/perl/ch-2.pl b/challenge-122/wlmb/perl/ch-2.pl
new file mode 100755
index 0000000000..926854827a
--- /dev/null
+++ b/challenge-122/wlmb/perl/ch-2.pl
@@ -0,0 +1,24 @@
+#!/usr/bin/env perl
+# Perl weekly challenge 122
+# Task 2:
+# Basketball Points
+# See https://wlmb.github.io/2021/07/19/PWC122/#task-2-basketball-points
+use strict;
+use warnings;
+use v5.12;
+use Memoize;
+memoize("points");
+
+foreach (@ARGV){
+ say "Input: $_\nOutput:\n\t", join "\n\t", map {join " ", @$_} points($_);
+}
+sub points{
+ my $s=shift;
+ return () if $s<=0;
+ # Append a 1, 2 or 3 point throw to the previous points
+ my @result=((map {my @x=@$_;push @x,1; [@x]}points($s-1)),
+ (map {my @x=@$_;push @x,2; [@x]}points($s-2)),
+ (map {my @x=@$_;push @x,3; [@x]}points($s-3)));
+ push @result, [$s] if $s<=3;
+ return @result;
+}