From 8241848f1fe7590078c04f8a915ce34585683894 Mon Sep 17 00:00:00 2001 From: "E. Choroba" Date: Sat, 25 Jan 2020 19:54:49 +0100 Subject: 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. --- challenge-044/e-choroba/blog.txt | 1 + challenge-044/e-choroba/perl/ch-1.pl | 3 ++- challenge-044/e-choroba/perl/ch-2.pl | 4 +--- 3 files changed, 4 insertions(+), 4 deletions(-) create mode 100644 challenge-044/e-choroba/blog.txt 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} }; -- cgit