aboutsummaryrefslogtreecommitdiff
path: root/challenge-044
diff options
context:
space:
mode:
authorE. Choroba <choroba@matfyz.cz>2020-01-25 19:54:49 +0100
committerE. Choroba <choroba@matfyz.cz>2020-01-25 19:54:49 +0100
commit8241848f1fe7590078c04f8a915ce34585683894 (patch)
tree00b07127b0a5b8629f0bbcd2e4f8f24e73032603 /challenge-044
parentc926febeed866713d723c1d1aeeab62ccb0fce1f (diff)
downloadperlweeklychallenge-club-8241848f1fe7590078c04f8a915ce34585683894.tar.gz
perlweeklychallenge-club-8241848f1fe7590078c04f8a915ce34585683894.tar.bz2
perlweeklychallenge-club-8241848f1fe7590078c04f8a915ce34585683894.zip
Add a link to E. Choroba's blog about 044
Also, update the solutions: don't skip the last mask in task 1 and don't use an additional variable for a negligible reduction of the hash.
Diffstat (limited to 'challenge-044')
-rw-r--r--challenge-044/e-choroba/blog.txt1
-rwxr-xr-xchallenge-044/e-choroba/perl/ch-1.pl3
-rwxr-xr-xchallenge-044/e-choroba/perl/ch-2.pl4
3 files changed, 4 insertions, 4 deletions
diff --git a/challenge-044/e-choroba/blog.txt b/challenge-044/e-choroba/blog.txt
new file mode 100644
index 0000000000..e261bf0ba3
--- /dev/null
+++ b/challenge-044/e-choroba/blog.txt
@@ -0,0 +1 @@
+http://blogs.perl.org/users/e_choroba/2020/01/perl-weekly-challenge-044-one-hundred-two-hundred.html
diff --git a/challenge-044/e-choroba/perl/ch-1.pl b/challenge-044/e-choroba/perl/ch-1.pl
index a57b89a121..13e45ea8cd 100755
--- a/challenge-044/e-choroba/perl/ch-1.pl
+++ b/challenge-044/e-choroba/perl/ch-1.pl
@@ -39,9 +39,10 @@ sub increment {
}
my @mask = (NOTHING) x (@digits - 1);
-while (grep $_ != MINUS, @mask) {
+while (1) {
my $expression = apply(\@mask);
say $expression if 100 == evaluate($expression);
+ last unless grep $_ != MINUS, @mask;
increment(\@mask);
}
diff --git a/challenge-044/e-choroba/perl/ch-2.pl b/challenge-044/e-choroba/perl/ch-2.pl
index 6e63e62be3..5bf43cacf3 100755
--- a/challenge-044/e-choroba/perl/ch-2.pl
+++ b/challenge-044/e-choroba/perl/ch-2.pl
@@ -5,12 +5,10 @@ use feature qw{ say };
my %possibilities = (1 => []);
while (! exists $possibilities{200}) {
- my %next;
for my $p (keys %possibilities) {
- $next{ $_ } = [ @{ $possibilities{$p} }, $p ]
+ $possibilities{ $_ } ||= [ @{ $possibilities{$p} }, $p ]
for $p + 1, $p * 2;
}
- %possibilities = %next;
}
my @moves = @{ $possibilities{200} };