From f1ea467485df825b48e023ae7efb9cc031e94e8a Mon Sep 17 00:00:00 2001 From: Abigail Date: Mon, 1 Nov 2021 18:34:09 +0100 Subject: Perl solution for week 137. part 2 --- challenge-137/abigail/perl/ch-2.pl | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 challenge-137/abigail/perl/ch-2.pl (limited to 'challenge-137') diff --git a/challenge-137/abigail/perl/ch-2.pl b/challenge-137/abigail/perl/ch-2.pl new file mode 100644 index 0000000000..294272ec68 --- /dev/null +++ b/challenge-137/abigail/perl/ch-2.pl @@ -0,0 +1,30 @@ +#!/opt/perl/bin/perl + +use 5.032; + +use strict; +use warnings; +no warnings 'syntax'; + +use experimental 'signatures'; +use experimental 'lexical_subs'; + +# +# See ../README.md +# + +# +# Run as: perl ch-2.pl < input-file +# + +# +# Note that the challenge says we can terminate the process of iterating +# if we have had 500 iterations. We will never hit that: for all numbers +# between 10 and 1000, we either reach a palindrome or exceed 10_000_000 +# long before hitting the 500th iteration (11 iterations is the maximum +# amount of iterations we need). So, we just won't bother tracking the +# number of iterations. +# + +sub l ($n) {$n >= 10_000_000 ? 1 : $n eq reverse ($n) ? 0 : l ($n + reverse $n)} +say l s/\n//r while <>; -- cgit