diff options
| author | Luis Mochan <mochan@fis.unam.mx> | 2021-07-19 14:30:14 -0500 |
|---|---|---|
| committer | Luis Mochan <mochan@fis.unam.mx> | 2021-07-19 14:30:14 -0500 |
| commit | 14992ebe13aefb15deab8ce9f2c48748f70dbf61 (patch) | |
| tree | d2cd19b78bf33115f4115ef258bca1866834f46a /challenge-122 | |
| parent | e542ee52b8f6be5d340550000cbe98f4b2aefb1e (diff) | |
| download | perlweeklychallenge-club-14992ebe13aefb15deab8ce9f2c48748f70dbf61.tar.gz perlweeklychallenge-club-14992ebe13aefb15deab8ce9f2c48748f70dbf61.tar.bz2 perlweeklychallenge-club-14992ebe13aefb15deab8ce9f2c48748f70dbf61.zip | |
Solve PWC 122
Diffstat (limited to 'challenge-122')
| -rw-r--r-- | challenge-122/wlmb/blog.txt | 1 | ||||
| -rwxr-xr-x | challenge-122/wlmb/perl/ch-1.pl | 17 | ||||
| -rwxr-xr-x | challenge-122/wlmb/perl/ch-2.pl | 24 |
3 files changed, 42 insertions, 0 deletions
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; +} |
