aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--challenge-138/luca-ferrari/raku/ch-2.p616
1 files changed, 16 insertions, 0 deletions
diff --git a/challenge-138/luca-ferrari/raku/ch-2.p6 b/challenge-138/luca-ferrari/raku/ch-2.p6
new file mode 100644
index 0000000000..72e7295a70
--- /dev/null
+++ b/challenge-138/luca-ferrari/raku/ch-2.p6
@@ -0,0 +1,16 @@
+#!raku
+
+sub MAIN( Int:D $n where { $n > 0 } ) {
+ my $qrt = $n.sqrt;
+ my @digits = $n.split( '', :skip-empty );
+
+ # short circuit: esay case
+ 1.say and exit if @digits.sum == $qrt;
+
+ # try to aggregate from left to right
+ for 1 ..^ @digits.elems {
+ last if @digits[ 0 .. $_ ].join.Int > $qrt;
+ '1'.say and exit if @digits[ 0 .. $_ ].join + @digits[ $_ + 1 .. * - 1 ].sum == $qrt;
+ }
+
+}