aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--challenge-261/barroff/bqn/ch-1.bqn9
-rw-r--r--challenge-261/barroff/bqn/ch-2.bqn7
-rw-r--r--challenge-261/barroff/julia/ch-1.jl14
-rw-r--r--challenge-261/barroff/julia/ch-2.jl13
-rw-r--r--challenge-261/barroff/raku/ch-1.p624
-rw-r--r--challenge-261/barroff/raku/ch-2.p623
6 files changed, 90 insertions, 0 deletions
diff --git a/challenge-261/barroff/bqn/ch-1.bqn b/challenge-261/barroff/bqn/ch-1.bqn
new file mode 100644
index 0000000000..3bc302be2a
--- /dev/null
+++ b/challenge-261/barroff/bqn/ch-1.bqn
@@ -0,0 +1,9 @@
+#/usr/bin/env bqn
+
+DigitSum ← { (10|𝕩) + (0⊸<)◶ 0‿𝕊 𝕩(⌊∘÷)10 }
+ElementDigitSum ← +´-(+´ DigitSum¨)
+
+•Show ElementDigitSum 1‿2‿3‿45
+•Show ElementDigitSum 1‿12‿3
+•Show ElementDigitSum 1‿2‿3‿4
+•Show ElementDigitSum 236‿416‿336‿350
diff --git a/challenge-261/barroff/bqn/ch-2.bqn b/challenge-261/barroff/bqn/ch-2.bqn
new file mode 100644
index 0000000000..bc5825c0b7
--- /dev/null
+++ b/challenge-261/barroff/bqn/ch-2.bqn
@@ -0,0 +1,7 @@
+#/usr/bin/env bqn
+
+MultiplyByTwo ← { (∨´𝕨⊸=)◶𝕨‿((2×𝕨)𝕊⊢) 𝕩 }
+
+•Show 3 MultiplyByTwo 5‿3‿6‿1‿12
+•Show 1 MultiplyByTwo 1‿2‿4‿3
+•Show 2 MultiplyByTwo 5‿6‿7
diff --git a/challenge-261/barroff/julia/ch-1.jl b/challenge-261/barroff/julia/ch-1.jl
new file mode 100644
index 0000000000..e80f7b67ca
--- /dev/null
+++ b/challenge-261/barroff/julia/ch-1.jl
@@ -0,0 +1,14 @@
+#!/usr/bin/env julia
+
+using Test: @test, @testset
+
+function element_digit_sim(ints::Vector{T})::Int where {T<:Integer}
+ sum(ints) - sum([sum([parse(Int, y) for y in split(string(x), "")]) for x in ints])
+end
+
+@testset "count even digits number" begin
+ @test element_digit_sim([1, 2, 3, 45]) == 36
+ @test element_digit_sim([1, 12, 3]) == 9
+ @test element_digit_sim([1, 2, 3, 4]) == 0
+ @test element_digit_sim([236, 416, 336, 350]) == 1296
+end
diff --git a/challenge-261/barroff/julia/ch-2.jl b/challenge-261/barroff/julia/ch-2.jl
new file mode 100644
index 0000000000..15caccf46d
--- /dev/null
+++ b/challenge-261/barroff/julia/ch-2.jl
@@ -0,0 +1,13 @@
+#!/usr/bin/env julia
+
+using Test: @test, @testset
+
+function multiply_by_two(start::T, ints::Vector{T})::Int where {T<:Integer}
+ start in ints ? multiply_by_two(2 * start, ints) : start
+end
+
+@testset "count even digits number" begin
+ @test multiply_by_two(3, [5, 3, 6, 1, 12]) == 24
+ @test multiply_by_two(1, [1, 2, 4, 3]) == 8
+ @test multiply_by_two(2, [5, 6, 7]) == 2
+end
diff --git a/challenge-261/barroff/raku/ch-1.p6 b/challenge-261/barroff/raku/ch-1.p6
new file mode 100644
index 0000000000..5ad67d7682
--- /dev/null
+++ b/challenge-261/barroff/raku/ch-1.p6
@@ -0,0 +1,24 @@
+#!/usr/bin/env raku
+
+use v6.d;
+
+sub element-digit-sum(@ints --> Int:D) {
+ sum(@ints) - sum(map({ sum($_.Str.comb.map: -> $x { $x.Int}) }, @ints))
+}
+
+#| Run test cases
+multi sub MAIN('test') {
+ use Test;
+ plan 4;
+
+ is element-digit-sum([1, 2, 3, 45]), 36, 'works for (1, 2, 3, 45)';
+ is element-digit-sum([1, 12, 3]), 9, 'works for (1, 12, 3)';
+ is element-digit-sum([1, 2, 3, 4]), 0, 'works for (1, 2, 3, 4)';
+ is element-digit-sum([236, 416, 336, 350]), 1296,
+ 'works for (236, 416, 336, 350)';
+}
+
+#| Take user provided number like 10 1 111 24 1000
+multi sub MAIN(*@ints) {
+ say element-digit-sum(@ints);
+}
diff --git a/challenge-261/barroff/raku/ch-2.p6 b/challenge-261/barroff/raku/ch-2.p6
new file mode 100644
index 0000000000..0e203e3ff5
--- /dev/null
+++ b/challenge-261/barroff/raku/ch-2.p6
@@ -0,0 +1,23 @@
+#!/usr/bin/env raku
+
+use v6.d;
+
+sub multiply-by-two(Int:D $start, @ints --> Int:D) {
+ $start (elem) @ints ?? multiply-by-two(2 * $start, @ints) !! $start;
+}
+
+#| Run test cases
+multi sub MAIN('test') {
+ use Test;
+ plan 3;
+
+ is multiply-by-two(3, [5,3,6,1,12]), 24, 'works for 3 and (5, 3, 6, 1, 12)';
+ is multiply-by-two(1, [1,2,4,3]), 8, 'works for 1 and (1, 2, 4, 3)';
+ is multiply-by-two(2, [5,6,7]), 2, 'works for 2 and (5,6,7)';
+}
+
+#| Take user provided number like 10 1 111 24 1000
+multi sub MAIN(Int:D $start, *@ints) {
+ my Int:D @integer_ints = @ints.map: *.Int;
+ say multiply-by-two($start.Int, @integer_ints);
+}