aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorvinodk89 <vinodkk89@gmail.com>2025-10-22 13:51:58 +0530
committervinodk89 <vinodkk89@gmail.com>2025-10-22 13:51:58 +0530
commitd1ec43fa1c3f5e08e608c71c8d2a0b6ddb873d91 (patch)
treece7fc3105edeeaf9075a57b596473d6bbe889f67
parent7d617633d2e7cf8300ff45019eb7b156da137dac (diff)
downloadperlweeklychallenge-club-d1ec43fa1c3f5e08e608c71c8d2a0b6ddb873d91.tar.gz
perlweeklychallenge-club-d1ec43fa1c3f5e08e608c71c8d2a0b6ddb873d91.tar.bz2
perlweeklychallenge-club-d1ec43fa1c3f5e08e608c71c8d2a0b6ddb873d91.zip
Solution for Challenge-344 (Raku)
-rw-r--r--challenge-344/vinod-k/raku/ch-1.raku47
1 files changed, 47 insertions, 0 deletions
diff --git a/challenge-344/vinod-k/raku/ch-1.raku b/challenge-344/vinod-k/raku/ch-1.raku
new file mode 100644
index 0000000000..fb056f2847
--- /dev/null
+++ b/challenge-344/vinod-k/raku/ch-1.raku
@@ -0,0 +1,47 @@
+use v6;
+use Test;
+
+sub add-to-array-form (
+ @ints is raw,
+ Int $x
+) returns List {
+ my $int-form = @ints.join('').Int;
+ my $sum = $int-form + $x;
+ return $sum.Str.comb.map(*.Int).Array;
+}
+
+# Testing
+
+sub MAIN {
+ plan 5;
+
+ my @ints1 = (1, 2, 3, 4);
+ my $x1 = 12;
+ my @expected1 = (1, 2, 4, 6);
+ is-deeply add-to-array-form(@ints1, $x1), @expected1,
+ "Test 1: (1,2,3,4) + 12 should be (1, 2, 4, 6)";
+
+ my @ints2 = (2, 7, 4);
+ my $x2 = 181;
+ my @expected2 = (4, 5, 5);
+ is-deeply add-to-array-form(@ints2, $x2), @expected2,
+ "Test 1: (2, 7, 4) + 181 should be (4, 5, 5)";
+
+ my @ints3 = (9, 9, 9);
+ my $x3 = 1;
+ my @expected3 = (1, 0, 0, 0);
+ is-deeply add-to-array-form(@ints3, $x3), @expected3,
+ "Test 1: (9, 9, 9) + 1 should be (1, 0, 0, 0)";
+
+ my @ints4 = (1, 0, 0, 0, 0);
+ my $x4 = 9999;
+ my @expected4 = (1, 9, 9, 9, 9);
+ is-deeply add-to-array-form(@ints4, $x4), @expected4,
+ "Test 1: (1, 0, 0, 0, 0) + 9999 should be (1, 9, 9, 9, 9)";
+
+ my @ints5 = (0);
+ my $x5 = 1000;
+ my @expected5 = (1, 0, 0, 0);
+ is-deeply add-to-array-form(@ints5, $x5), @expected5,
+ "Test 1: (0) + 12 should be (1, 0, 0, 0)";
+} \ No newline at end of file