aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorE. Choroba <choroba@matfyz.cz>2020-03-15 23:39:52 +0100
committerE. Choroba <choroba@matfyz.cz>2020-03-15 23:39:52 +0100
commit5bdc4f2a7dc275c0247c728a7403da54f095589b (patch)
treea096dd84bbc73f1c2f2716d0fb252d3a76694fa2
parent6e0ac5671e755a57ef1627ad68514281acefcf00 (diff)
downloadperlweeklychallenge-club-5bdc4f2a7dc275c0247c728a7403da54f095589b.tar.gz
perlweeklychallenge-club-5bdc4f2a7dc275c0247c728a7403da54f095589b.tar.bz2
perlweeklychallenge-club-5bdc4f2a7dc275c0247c728a7403da54f095589b.zip
Add blog post by E. Choroba about 051 (3Sum and Colourful Numbers)
Also, simplify the solution of the second task: we don't need to pad the array.
-rw-r--r--challenge-051/e-choroba/blog.txt1
-rwxr-xr-xchallenge-051/e-choroba/perl/ch-2.pl4
2 files changed, 2 insertions, 3 deletions
diff --git a/challenge-051/e-choroba/blog.txt b/challenge-051/e-choroba/blog.txt
new file mode 100644
index 0000000000..66ce5ed9d2
--- /dev/null
+++ b/challenge-051/e-choroba/blog.txt
@@ -0,0 +1 @@
+http://blogs.perl.org/users/e_choroba/2020/03/perl-weekly-challenge-051-3-sum-and-colourful-numbers.html
diff --git a/challenge-051/e-choroba/perl/ch-2.pl b/challenge-051/e-choroba/perl/ch-2.pl
index 47505bbab9..b911cb2012 100755
--- a/challenge-051/e-choroba/perl/ch-2.pl
+++ b/challenge-051/e-choroba/perl/ch-2.pl
@@ -12,9 +12,7 @@ sub is_colorful_number {
my $count = 0;
for my $length (1 .. $max_length) {
for my $pos (0 .. $max_length - $length) {
- my @pattern = (
- (0) x $pos, (1) x $length, (0) x ($max_length - $pos - $length)
- );
+ my @pattern = ((0) x $pos, (1) x $length);
undef $uniq{
product((split //, $n)[ grep $pattern[$_], 0 .. $#pattern ])
};