diff options
| author | Mohammad S Anwar <mohammad.anwar@yahoo.com> | 2021-11-03 08:33:22 +0000 |
|---|---|---|
| committer | Mohammad S Anwar <mohammad.anwar@yahoo.com> | 2021-11-03 08:33:22 +0000 |
| commit | adad9a7871dde197ae54828fe928fa9aa1e3592d (patch) | |
| tree | a5935387dcf9c9d85681f5a483409c2439f6584c /challenge-137 | |
| parent | 44fe1238f7ff9315570e0cba709213130e0add3a (diff) | |
| download | perlweeklychallenge-club-adad9a7871dde197ae54828fe928fa9aa1e3592d.tar.gz perlweeklychallenge-club-adad9a7871dde197ae54828fe928fa9aa1e3592d.tar.bz2 perlweeklychallenge-club-adad9a7871dde197ae54828fe928fa9aa1e3592d.zip | |
- Added solution by Robert DiCicco.
Diffstat (limited to 'challenge-137')
| -rw-r--r-- | challenge-137/robert-dicicco/perl/ch-2.pl | 40 |
1 files changed, 40 insertions, 0 deletions
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 = <STDIN>; +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"); +} |
