aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMohammad S Anwar <Mohammad.Anwar@yahoo.com>2021-06-08 15:36:21 +0100
committerGitHub <noreply@github.com>2021-06-08 15:36:21 +0100
commit2eaf6c909bd6146f80b08c6142f33dcf570a03da (patch)
tree3b83fcc7d8a7521b1527749b5b62e158c4c64e85
parentedebac2ae86d348d1a495805993d92cd9d61fa0c (diff)
parent4a2555ce1cc8edebd95991663e6a260a2c449fce (diff)
downloadperlweeklychallenge-club-2eaf6c909bd6146f80b08c6142f33dcf570a03da.tar.gz
perlweeklychallenge-club-2eaf6c909bd6146f80b08c6142f33dcf570a03da.tar.bz2
perlweeklychallenge-club-2eaf6c909bd6146f80b08c6142f33dcf570a03da.zip
Merge pull request #4215 from stuart-little/stuart-little_116_perl
1st commit on 116_perl
-rwxr-xr-xchallenge-116/stuart-little/perl/ch-1.pl27
-rwxr-xr-xchallenge-116/stuart-little/perl/ch-2.pl10
2 files changed, 37 insertions, 0 deletions
diff --git a/challenge-116/stuart-little/perl/ch-1.pl b/challenge-116/stuart-little/perl/ch-1.pl
new file mode 100755
index 0000000000..dcb46bc82e
--- /dev/null
+++ b/challenge-116/stuart-little/perl/ch-1.pl
@@ -0,0 +1,27 @@
+#!/usr/bin/env perl
+use warnings;
+use v5.12;
+
+# run <script> <number>
+
+use feature qw(signatures);
+no warnings qw(experimental::signatures);
+
+use List::Util qw(first);
+
+sub firstOver($s1,$s2) {
+ my @runs = map { my $l = $_; my @run = map { $_ + $s1 } (0..$l); \@run } (0..length($s2));
+ return first { length(join "", @{$_}) >= length($s2) } @runs;
+}
+
+sub inits($s) {
+ my @inits=map { substr($s,0,$_) } (1..length $s);
+ return \@inits;
+}
+
+sub consecSplit($s) {
+ return first { join("", @{$_}) eq $s } map {firstOver($_,$s)} @{inits($s)};
+}
+
+my @split=@{consecSplit($ARGV[0])};
+say "@split";
diff --git a/challenge-116/stuart-little/perl/ch-2.pl b/challenge-116/stuart-little/perl/ch-2.pl
new file mode 100755
index 0000000000..187220241f
--- /dev/null
+++ b/challenge-116/stuart-little/perl/ch-2.pl
@@ -0,0 +1,10 @@
+#!/usr/bin/env perl
+use warnings;
+use v5.12;
+
+# run <script> <number>
+
+use List::Util qw(sum0);
+
+my $digSqSum = sum0 map { $_ ** 2 } split //, $ARGV[0];
+say 0+(int(sqrt $digSqSum) ** 2 == $digSqSum);