aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCY Fung <fungcheokyin@gmail.com>2023-07-10 06:39:44 +0800
committerCY Fung <fungcheokyin@gmail.com>2023-07-10 06:39:44 +0800
commit086fe4c1433069d0e47f3fc49a188653f697a95a (patch)
tree28a81a2a3c0d425cf0823794e0a5c87c86428c9a
parent73d8b4a974d56b01963294e8c3c775dec7e46bbd (diff)
downloadperlweeklychallenge-club-086fe4c1433069d0e47f3fc49a188653f697a95a.tar.gz
perlweeklychallenge-club-086fe4c1433069d0e47f3fc49a188653f697a95a.tar.bz2
perlweeklychallenge-club-086fe4c1433069d0e47f3fc49a188653f697a95a.zip
Week 224 Task 2
-rw-r--r--challenge-224/cheok-yin-fung/perl/ch-2.pl33
1 files changed, 33 insertions, 0 deletions
diff --git a/challenge-224/cheok-yin-fung/perl/ch-2.pl b/challenge-224/cheok-yin-fung/perl/ch-2.pl
new file mode 100644
index 0000000000..d82a13a50d
--- /dev/null
+++ b/challenge-224/cheok-yin-fung/perl/ch-2.pl
@@ -0,0 +1,33 @@
+use v5.30.0;
+use warnings;
+use List::Util qw/max/;
+
+sub an {
+ my $n = $_[0];
+ for my $first (1..length($n)/2) {
+ for my $second (1..length($n)/2) {
+ my $x = substr($n, 0, $first);
+ my $y = substr($n, $first, $second);
+ my $sum = $first + $second;
+ my @arr = ($x, $y);
+ while ($sum < length $n) {
+ my $z = $x+$y;
+ push @arr, $z;
+ $sum += length($z);
+ $x = $y;
+ $y = $z;
+ }
+ return 1 if ($n eq join "", @arr) && $#arr > 1;
+ }
+ }
+ return 0;
+}
+
+
+use Test::More tests=>5;
+ok an(112358);
+ok !an(12345);
+ok an(199100199);
+ok an(199100199299);
+ok !an(1564898);
+