From adad9a7871dde197ae54828fe928fa9aa1e3592d Mon Sep 17 00:00:00 2001 From: Mohammad S Anwar Date: Wed, 3 Nov 2021 08:33:22 +0000 Subject: - Added solution by Robert DiCicco. --- challenge-137/robert-dicicco/perl/ch-2.pl | 40 +++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 challenge-137/robert-dicicco/perl/ch-2.pl (limited to 'challenge-137') diff --git a/challenge-137/robert-dicicco/perl/ch-2.pl b/challenge-137/robert-dicicco/perl/ch-2.pl new file mode 100644 index 0000000000..d57447df39 --- /dev/null +++ b/challenge-137/robert-dicicco/perl/ch-2.pl @@ -0,0 +1,40 @@ +#!/usr/bin/env perl + +use strict; +use warnings; + +# Author: Robert DiCicco +# Date: 01-NOV-2021 +# Challenge 137 Lychrel + +print("Enter the first number: "); +my $fnum = ; +chomp($fnum); + +my $found = 0; +my $iterations = 0; +my $snum = 0; + +while (( $found == 0) and ($iterations < 500) and ($snum < 10_000_000)) { + $iterations++; + $snum = reverse("$fnum"); + my $mysum = $fnum + $snum; + my $revsum = reverse($mysum); + $snum =~ s/^\s+//; #remove leading spaces + print "$fnum + $snum = $mysum\n"; + + if ( $mysum == $revsum) { + print("Palindrome found after $iterations iterations\n"); + $found++; + } else { + $fnum = $mysum; + } +} + +if ($iterations == 500 ) { + print("Reached total iteration limit of 500\n"); +} + +if ($snum >= 10_000_000) { + print("Value has exceeded limit of 10_000_000\n"); +} -- cgit