From 51feed7f6f1ba280658615d36ee2f7ccf77b5000 Mon Sep 17 00:00:00 2001 From: Luis Mochan Date: Tue, 13 Jul 2021 23:17:19 -0500 Subject: Correct typo --- challenge-121/wlmb/perl/ch-2-helper.pl | 4 ++-- challenge-121/wlmb/perl/ch-2.pl | 4 ++-- challenge-121/wlmb/perl/ch-2a.pl | 4 ++-- challenge-121/wlmb/perl/ch-2b.pl | 4 ++-- 4 files changed, 8 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; -- cgit From 14992ebe13aefb15deab8ce9f2c48748f70dbf61 Mon Sep 17 00:00:00 2001 From: Luis Mochan Date: Mon, 19 Jul 2021 14:30:14 -0500 Subject: Solve PWC 122 --- challenge-122/wlmb/blog.txt | 1 + challenge-122/wlmb/perl/ch-1.pl | 17 +++++++++++++++++ challenge-122/wlmb/perl/ch-2.pl | 24 ++++++++++++++++++++++++ 3 files changed, 42 insertions(+) create mode 100644 challenge-122/wlmb/blog.txt create mode 100755 challenge-122/wlmb/perl/ch-1.pl create mode 100755 challenge-122/wlmb/perl/ch-2.pl 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; +} -- cgit