aboutsummaryrefslogtreecommitdiff
path: root/challenge-137/abigail
diff options
context:
space:
mode:
authorAbigail <abigail@abigail.be>2021-11-01 18:34:09 +0100
committerAbigail <abigail@abigail.be>2021-11-01 18:58:54 +0100
commitf1ea467485df825b48e023ae7efb9cc031e94e8a (patch)
tree0e7f2cf02f3182db98550e266caaa1ffdc766e72 /challenge-137/abigail
parent4cb0f7b8bc788572a1ff715a58e88ad2635d3a9d (diff)
downloadperlweeklychallenge-club-f1ea467485df825b48e023ae7efb9cc031e94e8a.tar.gz
perlweeklychallenge-club-f1ea467485df825b48e023ae7efb9cc031e94e8a.tar.bz2
perlweeklychallenge-club-f1ea467485df825b48e023ae7efb9cc031e94e8a.zip
Perl solution for week 137. part 2
Diffstat (limited to 'challenge-137/abigail')
-rw-r--r--challenge-137/abigail/perl/ch-2.pl30
1 files changed, 30 insertions, 0 deletions
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 <>;