aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorScott Sotka <ssotka@barracuda.com>2024-01-12 10:33:42 -0800
committerScott Sotka <ssotka@barracuda.com>2024-01-12 10:33:42 -0800
commit41b69155a84eeabec4adef1bbf8c88814a69034d (patch)
tree10915d0877680959ba752d82734096b8991ae12f
parent797c77ce54a624bb8caeab0c95f4582179312249 (diff)
downloadperlweeklychallenge-club-41b69155a84eeabec4adef1bbf8c88814a69034d.tar.gz
perlweeklychallenge-club-41b69155a84eeabec4adef1bbf8c88814a69034d.tar.bz2
perlweeklychallenge-club-41b69155a84eeabec4adef1bbf8c88814a69034d.zip
CH-251 my first contribution
-rw-r--r--challenge-251/bn-ssotka/README2
-rwxr-xr-xchallenge-251/bn-ssotka/raku/ch-251.raku28
2 files changed, 30 insertions, 0 deletions
diff --git a/challenge-251/bn-ssotka/README b/challenge-251/bn-ssotka/README
new file mode 100644
index 0000000000..026d85de25
--- /dev/null
+++ b/challenge-251/bn-ssotka/README
@@ -0,0 +1,2 @@
+Solution by Scott Sotka
+
diff --git a/challenge-251/bn-ssotka/raku/ch-251.raku b/challenge-251/bn-ssotka/raku/ch-251.raku
new file mode 100755
index 0000000000..0737dcd5f5
--- /dev/null
+++ b/challenge-251/bn-ssotka/raku/ch-251.raku
@@ -0,0 +1,28 @@
+#!/usr/bin/env raku
+
+# Write a script to find the concatenation value of the given array.
+
+# The concatenation of two numbers is the number formed by concatenating their numerals.
+
+# For example, the concatenation of 10, 21 is 1021.
+# The concatenation value of @ints is initially equal to 0.
+# Perform this operation until @ints becomes empty:
+
+# If there exists more than one number in @ints, pick the first element
+# and last element in @ints respectively and add the value of their
+# concatenation to the concatenation value of @ints, then delete the
+# first and last element from @ints.
+
+# If one element exists, add its value to the concatenation value of
+# @ints, then delete it.
+
+sub concat (@ints) {
+ say "Got ",@ints;
+ return 0 unless @ints;
+ return @ints[0] if @ints == 1;
+ return (@ints[0].Str ~ @ints[*-1].Str).Int + concat(@ints[1..*-2]);
+}
+
+sub MAIN (*@ints){
+ say concat(@ints);
+}