From 41b69155a84eeabec4adef1bbf8c88814a69034d Mon Sep 17 00:00:00 2001 From: Scott Sotka Date: Fri, 12 Jan 2024 10:33:42 -0800 Subject: CH-251 my first contribution --- challenge-251/bn-ssotka/README | 2 ++ challenge-251/bn-ssotka/raku/ch-251.raku | 28 ++++++++++++++++++++++++++++ 2 files changed, 30 insertions(+) create mode 100644 challenge-251/bn-ssotka/README create mode 100755 challenge-251/bn-ssotka/raku/ch-251.raku 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); +} -- cgit From 6a27c4c9e9491b1ab0a239703dbaf38d977c221d Mon Sep 17 00:00:00 2001 From: Scott Sotka Date: Fri, 12 Jan 2024 10:41:41 -0800 Subject: CH-251 made main a multi, if no args, runs the test set --- challenge-251/bn-ssotka/raku/ch-251.raku | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/challenge-251/bn-ssotka/raku/ch-251.raku b/challenge-251/bn-ssotka/raku/ch-251.raku index 0737dcd5f5..f92e5fec8a 100755 --- a/challenge-251/bn-ssotka/raku/ch-251.raku +++ b/challenge-251/bn-ssotka/raku/ch-251.raku @@ -23,6 +23,14 @@ sub concat (@ints) { return (@ints[0].Str ~ @ints[*-1].Str).Int + concat(@ints[1..*-2]); } -sub MAIN (*@ints){ +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 -- cgit