aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMohammad Sajid Anwar <Mohammad.Anwar@yahoo.com>2024-01-12 18:45:11 +0000
committerGitHub <noreply@github.com>2024-01-12 18:45:11 +0000
commite9aab96c193dfd6fa7129bc8b88c7d336edde93c (patch)
tree6b5f19494357fc500de42433710d4da24801d954
parenta3f08d4507a5b1be24522b06c5de1b5efa1b363f (diff)
parent6a27c4c9e9491b1ab0a239703dbaf38d977c221d (diff)
downloadperlweeklychallenge-club-e9aab96c193dfd6fa7129bc8b88c7d336edde93c.tar.gz
perlweeklychallenge-club-e9aab96c193dfd6fa7129bc8b88c7d336edde93c.tar.bz2
perlweeklychallenge-club-e9aab96c193dfd6fa7129bc8b88c7d336edde93c.zip
Merge pull request #9385 from bn-ssotka/ssotka-251
CH-251 my first contribution
-rw-r--r--challenge-251/bn-ssotka/README2
-rwxr-xr-xchallenge-251/bn-ssotka/raku/ch-251.raku36
2 files changed, 38 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..f92e5fec8a
--- /dev/null
+++ b/challenge-251/bn-ssotka/raku/ch-251.raku
@@ -0,0 +1,36 @@
+#!/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]);
+}
+
+multi MAIN (*@ints){
+ say concat(@ints);
+}
+multi MAIN {
+ my @tests = ((6, 12, 25, 1),
+ (10, 7, 31, 5, 2, 2),
+ (1, 2, 10));
+ for @tests -> @t {
+ say concat(@t);
+ }
+} \ No newline at end of file