aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-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);