From e9c2946bf8e7d2b0e571a03ee44da5e4c6af3cdb Mon Sep 17 00:00:00 2001 From: Asher Harvey-Smith Date: Tue, 19 Mar 2024 14:52:03 +0000 Subject: raku solutions --- challenge-261/asherbhs/ch-1.raku | 8 ++++++++ challenge-261/asherbhs/ch-2.raku | 9 +++++++++ 2 files changed, 17 insertions(+) create mode 100644 challenge-261/asherbhs/ch-1.raku create mode 100644 challenge-261/asherbhs/ch-2.raku diff --git a/challenge-261/asherbhs/ch-1.raku b/challenge-261/asherbhs/ch-1.raku new file mode 100644 index 0000000000..ef62ff6e85 --- /dev/null +++ b/challenge-261/asherbhs/ch-1.raku @@ -0,0 +1,8 @@ +sub element-digit-sum(Int @ints --> Int) { + return abs @ints.sum - @ints».polymod(10 xx ∞)».sum.sum +} + +say element-digit-sum Array[Int].new(1, 2, 3, 45); +say element-digit-sum Array[Int].new(1, 12, 3); +say element-digit-sum Array[Int].new(1, 2, 3, 4); +say element-digit-sum Array[Int].new(236, 416, 336, 350); diff --git a/challenge-261/asherbhs/ch-2.raku b/challenge-261/asherbhs/ch-2.raku new file mode 100644 index 0000000000..2a1edcf4e6 --- /dev/null +++ b/challenge-261/asherbhs/ch-2.raku @@ -0,0 +1,9 @@ +sub multiply-by-two(Int @ints, Int $start --> Int) { + return $start ∈ @ints + ?? multiply-by-two(@ints, 2 * $start) + !! $start +} + +say multiply-by-two(Array[Int].new(5, 3, 6, 1, 12), 3); +say multiply-by-two(Array[Int].new(1, 2, 4, 3), 1); +say multiply-by-two(Array[Int].new(5, 6, 7), 2); -- cgit