aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMohammad Sajid Anwar <Mohammad.Anwar@yahoo.com>2025-02-11 11:04:09 +0000
committerGitHub <noreply@github.com>2025-02-11 11:04:09 +0000
commitd014e525746659cb201e841719c5248a96a3e0e9 (patch)
tree0441ac8abe5ca3aee76365aa78aaf173ffe48054
parenta4cc4b5322dda475bf4c0d18e87ee972cce7fe6f (diff)
parentf535f041d7d82dc4ce558870c879ef014c805af3 (diff)
downloadperlweeklychallenge-club-d014e525746659cb201e841719c5248a96a3e0e9.tar.gz
perlweeklychallenge-club-d014e525746659cb201e841719c5248a96a3e0e9.tar.bz2
perlweeklychallenge-club-d014e525746659cb201e841719c5248a96a3e0e9.zip
Merge pull request #11564 from Firedrake/rogerbw-challenge-308
RogerBW solutions for challenge no. 308
-rwxr-xr-xchallenge-308/roger-bell-west/crystal/ch-1.cr20
-rwxr-xr-xchallenge-308/roger-bell-west/crystal/ch-2.cr19
-rwxr-xr-xchallenge-308/roger-bell-west/javascript/ch-1.js29
-rwxr-xr-xchallenge-308/roger-bell-west/javascript/ch-2.js51
-rw-r--r--challenge-308/roger-bell-west/kotlin/ch-1.kt28
-rw-r--r--challenge-308/roger-bell-west/kotlin/ch-2.kt24
-rwxr-xr-xchallenge-308/roger-bell-west/lua/ch-1.lua43
-rwxr-xr-xchallenge-308/roger-bell-west/lua/ch-2.lua53
-rwxr-xr-xchallenge-308/roger-bell-west/perl/ch-1.pl17
-rwxr-xr-xchallenge-308/roger-bell-west/perl/ch-2.pl18
-rw-r--r--challenge-308/roger-bell-west/postscript/ch-1.ps78
-rw-r--r--challenge-308/roger-bell-west/postscript/ch-2.ps109
-rwxr-xr-xchallenge-308/roger-bell-west/python/ch-1.py21
-rwxr-xr-xchallenge-308/roger-bell-west/python/ch-2.py19
-rwxr-xr-xchallenge-308/roger-bell-west/raku/ch-1.p615
-rwxr-xr-xchallenge-308/roger-bell-west/raku/ch-2.p616
-rwxr-xr-xchallenge-308/roger-bell-west/ruby/ch-1.rb27
-rwxr-xr-xchallenge-308/roger-bell-west/ruby/ch-2.rb23
-rwxr-xr-xchallenge-308/roger-bell-west/rust/ch-1.rs26
-rwxr-xr-xchallenge-308/roger-bell-west/rust/ch-2.rs20
-rw-r--r--challenge-308/roger-bell-west/scala/ch-1.scala29
-rw-r--r--challenge-308/roger-bell-west/scala/ch-2.scala27
-rw-r--r--challenge-308/roger-bell-west/tests.json48
23 files changed, 760 insertions, 0 deletions
diff --git a/challenge-308/roger-bell-west/crystal/ch-1.cr b/challenge-308/roger-bell-west/crystal/ch-1.cr
new file mode 100755
index 0000000000..c6c72f0a73
--- /dev/null
+++ b/challenge-308/roger-bell-west/crystal/ch-1.cr
@@ -0,0 +1,20 @@
+#! /usr/bin/crystal
+
+def countcommon(a, b)
+ aa = Set.new(a)
+ bb = Set.new(b)
+ (aa & bb).size
+end
+
+require "spec"
+describe "countcommon" do
+ it "test_ex1" do
+ countcommon(["perl", "weekly", "challenge"], ["raku", "weekly", "challenge"]).should eq 2
+ end
+ it "test_ex2" do
+ countcommon(["perl", "raku", "python"], ["python", "java"]).should eq 1
+ end
+ it "test_ex3" do
+ countcommon(["guest", "contribution"], ["fun", "weekly", "challenge"]).should eq 0
+ end
+end
diff --git a/challenge-308/roger-bell-west/crystal/ch-2.cr b/challenge-308/roger-bell-west/crystal/ch-2.cr
new file mode 100755
index 0000000000..71ca4948d7
--- /dev/null
+++ b/challenge-308/roger-bell-west/crystal/ch-2.cr
@@ -0,0 +1,19 @@
+#! /usr/bin/crystal
+
+def decodexor(a, init)
+ ot = [ init ]
+ a.each do |v|
+ ot.push(ot[-1] ^ v)
+ end
+ ot
+end
+
+require "spec"
+describe "decodexor" do
+ it "test_ex1" do
+ decodexor([1, 2, 3], 1).should eq [1, 0, 2, 1]
+ end
+ it "test_ex2" do
+ decodexor([6, 2, 7, 3], 4).should eq [4, 2, 0, 7, 4]
+ end
+end
diff --git a/challenge-308/roger-bell-west/javascript/ch-1.js b/challenge-308/roger-bell-west/javascript/ch-1.js
new file mode 100755
index 0000000000..8ae2e45044
--- /dev/null
+++ b/challenge-308/roger-bell-west/javascript/ch-1.js
@@ -0,0 +1,29 @@
+#! /usr/bin/node
+
+"use strict"
+
+function countcommon(a, b) {
+ const aa = new Set(a);
+ const bb = new Set(b);
+ const intersect = new Set([...aa].filter(i => bb.has(i)));
+ return intersect.size;
+}
+
+if (countcommon(['perl', 'weekly', 'challenge'], ['raku', 'weekly', 'challenge']) == 2) {
+ process.stdout.write("Pass");
+} else {
+ process.stdout.write("FAIL");
+}
+process.stdout.write(" ");
+if (countcommon(['perl', 'raku', 'python'], ['python', 'java']) == 1) {
+ process.stdout.write("Pass");
+} else {
+ process.stdout.write("FAIL");
+}
+process.stdout.write(" ");
+if (countcommon(['guest', 'contribution'], ['fun', 'weekly', 'challenge']) == 0) {
+ process.stdout.write("Pass");
+} else {
+ process.stdout.write("FAIL");
+}
+process.stdout.write("\n");
diff --git a/challenge-308/roger-bell-west/javascript/ch-2.js b/challenge-308/roger-bell-west/javascript/ch-2.js
new file mode 100755
index 0000000000..2df8c21d87
--- /dev/null
+++ b/challenge-308/roger-bell-west/javascript/ch-2.js
@@ -0,0 +1,51 @@
+#! /usr/bin/node
+
+"use strict"
+
+// by Frank Tan
+// https://stackoverflow.com/questions/38400594/javascript-deep-comparison
+function deepEqual(a,b)
+{
+ if( (typeof a == 'object' && a != null) &&
+ (typeof b == 'object' && b != null) )
+ {
+ var count = [0,0];
+ for( var key in a) count[0]++;
+ for( var key in b) count[1]++;
+ if( count[0]-count[1] != 0) {return false;}
+ for( var key in a)
+ {
+ if(!(key in b) || !deepEqual(a[key],b[key])) {return false;}
+ }
+ for( var key in b)
+ {
+ if(!(key in a) || !deepEqual(b[key],a[key])) {return false;}
+ }
+ return true;
+ }
+ else
+ {
+ return a === b;
+ }
+}
+
+function decodexor(a, init) {
+ let out = [init];
+ for (let v of a) {
+ out.push(out[out.length-1] ^ v);
+ }
+ return out;
+}
+
+if (deepEqual(decodexor([1, 2, 3], 1), [1, 0, 2, 1])) {
+ process.stdout.write("Pass");
+} else {
+ process.stdout.write("FAIL");
+}
+process.stdout.write(" ");
+if (deepEqual(decodexor([6, 2, 7, 3], 4), [4, 2, 0, 7, 4])) {
+ process.stdout.write("Pass");
+} else {
+ process.stdout.write("FAIL");
+}
+process.stdout.write("\n");
diff --git a/challenge-308/roger-bell-west/kotlin/ch-1.kt b/challenge-308/roger-bell-west/kotlin/ch-1.kt
new file mode 100644
index 0000000000..b8ef34edb1
--- /dev/null
+++ b/challenge-308/roger-bell-west/kotlin/ch-1.kt
@@ -0,0 +1,28 @@
+fun countcommon(a: List<String>, b: List<String>): Int {
+ val aa = a.toSet()
+ val bb = b.toSet()
+ return aa.intersect(bb).toList().count()
+}
+
+fun main() {
+
+ if (countcommon(listOf("perl", "weekly", "challenge"), listOf("raku", "weekly", "challenge")) == 2) {
+ print("Pass")
+ } else {
+ print("Fail")
+ }
+ print(" ")
+ if (countcommon(listOf("perl", "raku", "python"), listOf("python", "java")) == 1) {
+ print("Pass")
+ } else {
+ print("Fail")
+ }
+ print(" ")
+ if (countcommon(listOf("guest", "contribution"), listOf("fun", "weekly", "challenge")) == 0) {
+ print("Pass")
+ } else {
+ print("Fail")
+ }
+ println("")
+
+}
diff --git a/challenge-308/roger-bell-west/kotlin/ch-2.kt b/challenge-308/roger-bell-west/kotlin/ch-2.kt
new file mode 100644
index 0000000000..5a05b0e322
--- /dev/null
+++ b/challenge-308/roger-bell-west/kotlin/ch-2.kt
@@ -0,0 +1,24 @@
+fun decodexor(a: List<Int>, nit: Int): List<Int> {
+ var out = ArrayList(listOf(nit))
+ for (v in a) {
+ out.add(out[out.size - 1] xor v)
+ }
+ return out.toList()
+}
+
+fun main() {
+
+ if (decodexor(listOf(1, 2, 3), 1) == listOf(1, 0, 2, 1)) {
+ print("Pass")
+ } else {
+ print("Fail")
+ }
+ print(" ")
+ if (decodexor(listOf(6, 2, 7, 3), 4) == listOf(4, 2, 0, 7, 4)) {
+ print("Pass")
+ } else {
+ print("Fail")
+ }
+ println("")
+
+}
diff --git a/challenge-308/roger-bell-west/lua/ch-1.lua b/challenge-308/roger-bell-west/lua/ch-1.lua
new file mode 100755
index 0000000000..de6796045b
--- /dev/null
+++ b/challenge-308/roger-bell-west/lua/ch-1.lua
@@ -0,0 +1,43 @@
+#! /usr/bin/lua
+
+function toset(a)
+ local p = {}
+ for _, c in ipairs(a) do
+ p[c] = true
+ end
+ return p
+end
+
+function countcommon(a, b)
+ local aa = toset(a)
+ local bb = toset(b)
+ local out = 0
+ for c, _ in pairs(aa) do
+ if bb[c] ~= nil then
+ out = out + 1
+ end
+ end
+ return out
+end
+
+if countcommon({"perl", "weekly", "challenge"}, {"raku", "weekly", "challenge"}) == 2 then
+ io.write("Pass")
+else
+ io.write("FAIL")
+end
+io.write(" ")
+
+if countcommon({"perl", "raku", "python"}, {"python", "java"}) == 1 then
+ io.write("Pass")
+else
+ io.write("FAIL")
+end
+io.write(" ")
+
+if countcommon({"guest", "contribution"}, {"fun", "weekly", "challenge"}) == 0 then
+ io.write("Pass")
+else
+ io.write("FAIL")
+end
+print("")
+
diff --git a/challenge-308/roger-bell-west/lua/ch-2.lua b/challenge-308/roger-bell-west/lua/ch-2.lua
new file mode 100755
index 0000000000..3febd0020e
--- /dev/null
+++ b/challenge-308/roger-bell-west/lua/ch-2.lua
@@ -0,0 +1,53 @@
+#! /usr/bin/lua
+
+-- by Michael Anderson at
+-- https://stackoverflow.com/questions/8722620/comparing-two-index-tables-by-index-value-in-lua
+-- modified by Roger
+function recursive_compare(t1,t2)
+ -- Use usual comparison first.
+ if t1==t2 then return true end
+ -- We only support non-default behavior for tables
+ if (type(t1)~="table") then return false end
+ -- They better have the same metatables
+ local mt1 = getmetatable(t1)
+ local mt2 = getmetatable(t2)
+ if( not recursive_compare(mt1,mt2) ) then return false end
+ -- Build list of all keys
+ local kk = {}
+ for k1, _ in pairs(t1) do
+ kk[k1] = true
+ end
+ for k2, _ in pairs(t2) do
+ kk[k2] = true
+ end
+ -- Check each key that exists in at least one table
+ for _, k in ipairs(kk) do
+ if (not recursive_compare(t1[k], t2[k])) then
+ return false
+ end
+ end
+ return true
+end
+
+function decodexor(a, init)
+ local out = { init }
+ for _, v in ipairs(a) do
+ table.insert(out, out[#out] ~ v)
+ end
+ return out
+end
+
+if recursive_compare(decodexor({1, 2, 3}, 1), {1, 0, 2, 1}) then
+ io.write("Pass")
+else
+ io.write("FAIL")
+end
+io.write(" ")
+
+if recursive_compare(decodexor({6, 2, 7, 3}, 4), {4, 2, 0, 7, 4}) then
+ io.write("Pass")
+else
+ io.write("FAIL")
+end
+print("")
+
diff --git a/challenge-308/roger-bell-west/perl/ch-1.pl b/challenge-308/roger-bell-west/perl/ch-1.pl
new file mode 100755
index 0000000000..bfe5d6fccc
--- /dev/null
+++ b/challenge-308/roger-bell-west/perl/ch-1.pl
@@ -0,0 +1,17 @@
+#! /usr/bin/perl
+
+use strict;
+use warnings;
+use experimental 'signatures';
+
+use Test::More tests => 3;
+
+is(countcommon(['perl', 'weekly', 'challenge'], ['raku', 'weekly', 'challenge']), 2, 'example 1');
+is(countcommon(['perl', 'raku', 'python'], ['python', 'java']), 1, 'example 2');
+is(countcommon(['guest', 'contribution'], ['fun', 'weekly', 'challenge']), 0, 'example 3');
+
+sub countcommon($a, $b) {
+ my %aa = map {$_ => 1} @{$a};
+ my %bb = map {$_ => 1} @{$b};
+ scalar grep {exists $bb{$_}} keys %aa;
+}
diff --git a/challenge-308/roger-bell-west/perl/ch-2.pl b/challenge-308/roger-bell-west/perl/ch-2.pl
new file mode 100755
index 0000000000..d3510ac2fc
--- /dev/null
+++ b/challenge-308/roger-bell-west/perl/ch-2.pl
@@ -0,0 +1,18 @@
+#! /usr/bin/perl
+
+use strict;
+use warnings;
+use experimental 'signatures';
+
+use Test::More tests => 2;
+
+is_deeply(decodexor([1, 2, 3], 1), [1, 0, 2, 1], 'example 1');
+is_deeply(decodexor([6, 2, 7, 3], 4), [4, 2, 0, 7, 4], 'example 2');
+
+sub decodexor($a, $init) {
+ my @out = ($init);
+ foreach my $v (@{$a}) {
+ push @out, $out[-1] ^ $v;
+ }
+ \@out;
+}
diff --git a/challenge-308/roger-bell-west/postscript/ch-1.ps b/challenge-308/roger-bell-west/postscript/ch-1.ps
new file mode 100644
index 0000000000..bc2025fb24
--- /dev/null
+++ b/challenge-308/roger-bell-west/postscript/ch-1.ps
@@ -0,0 +1,78 @@
+%!PS
+
+% begin included library code
+% see https://codeberg.org/Firedrake/postscript-libraries/
+/test.start {
+ print (:) print
+ /test.pass 0 def
+ /test.count 0 def
+} bind def
+
+/test {
+ /test.count test.count 1 add def
+ {
+ /test.pass test.pass 1 add def
+ } {
+ ( ) print
+ test.count (....) cvs print
+ (-fail) print
+ } ifelse
+} bind def
+
+/keys { % dict -> array of dict keys
+ [ exch
+ {
+ pop
+ } forall
+ ]
+} bind def
+
+/toset { % array -> dict of (value, true)
+ << exch
+ {
+ true
+ } forall
+ >>
+} bind def
+
+/test.end {
+ ( ) print
+ test.count 0 gt {
+ (Passed ) print
+ test.pass (...) cvs print
+ (/) print
+ test.count (...) cvs print
+ ( \() print
+ test.pass 100 mul test.count idiv (...) cvs print
+ (%\)) print
+ (\r\n) print
+ } if
+} bind def
+
+/set.intersection {
+ 4 dict begin
+ /s 0 dict def
+ /b exch def
+ /a exch def
+ a keys {
+ /k exch def
+ b k known {
+ s k true put
+ } if
+ } forall
+ s
+ end
+} bind def
+
+
+% end included library code
+
+/countcommon {
+ toset exch toset set.intersection length
+} bind def
+
+(countcommon) test.start
+[(perl) (weekly) (challenge)] [(raku) (weekly) (challenge)] countcommon 2 eq test
+[(perl) (raku) (python)] [(python) (java)] countcommon 1 eq test
+[(guest) (contribution)] [(fun) (weekly) (challenge)] countcommon 0 eq test
+test.end
diff --git a/challenge-308/roger-bell-west/postscript/ch-2.ps b/challenge-308/roger-bell-west/postscript/ch-2.ps
new file mode 100644
index 0000000000..4e943e4d08
--- /dev/null
+++ b/challenge-308/roger-bell-west/postscript/ch-2.ps
@@ -0,0 +1,109 @@
+%!PS
+
+% begin included library code
+% see https://codeberg.org/Firedrake/postscript-libraries/
+/test {
+ /test.count test.count 1 add def
+ {
+ /test.pass test.pass 1 add def
+ } {
+ ( ) print
+ test.count (....) cvs print
+ (-fail) print
+ } ifelse
+} bind def
+
+/test.start {
+ print (:) print
+ /test.pass 0 def
+ /test.count 0 def
+} bind def
+
+/test.end {
+ ( ) print
+ test.count 0 gt {
+ (Passed ) print
+ test.pass (...) cvs print
+ (/) print
+ test.count (...) cvs print
+ ( \() print
+ test.pass 100 mul test.count idiv (...) cvs print
+ (%\)) print
+ (\r\n) print
+ } if
+} bind def
+
+/deepeq {
+ 2 dict begin
+ /a exch def
+ /b exch def
+ a type b type eq {
+ a type /dicttype eq {
+ a length b length eq {
+ <<
+ a {
+ pop
+ true
+ } forall
+ b {
+ pop
+ true
+ } forall
+ >>
+ true exch
+ {
+ pop
+ dup a exch known {
+ dup b exch known {
+ dup a exch get exch b exch get deepeq not {
+ pop false
+ } if
+ } {
+ false
+ } ifelse
+ } {
+ false
+ } ifelse
+ } forall
+ } {
+ false
+ } ifelse
+ } {
+ a type dup /arraytype eq exch /stringtype eq or {
+ a length b length eq {
+ true
+ 0 1 a length 1 sub {
+ dup a exch get exch b exch get deepeq not {
+ pop false
+ exit
+ } if
+ } for
+ } {
+ false
+ } ifelse
+ } {
+ a b eq
+ } ifelse
+ } ifelse
+ } {
+ false
+ } ifelse
+ end
+} bind def
+
+
+% end included library code
+
+/decodexor {
+ [ exch
+ 3 -1 roll
+ {
+ exch dup 3 -1 roll xor
+ } forall
+ ]
+} bind def
+
+(decodexor) test.start
+[1 2 3] 1 decodexor [1 0 2 1] deepeq test
+[6 2 7 3] 4 decodexor [4 2 0 7 4] deepeq test
+test.end
diff --git a/challenge-308/roger-bell-west/python/ch-1.py b/challenge-308/roger-bell-west/python/ch-1.py
new file mode 100755
index 0000000000..639a3dbb4c
--- /dev/null
+++ b/challenge-308/roger-bell-west/python/ch-1.py
@@ -0,0 +1,21 @@
+#! /usr/bin/python3
+
+def countcommon(a, b):
+ aa = set(a)
+ bb = set(b)
+ return len(aa.intersection(bb))
+
+import unittest
+
+class TestCountcommon(unittest.TestCase):
+
+ def test_ex1(self):
+ self.assertEqual(countcommon(["perl", "weekly", "challenge"], ["raku", "weekly", "challenge"]), 2, 'example 1')
+
+ def test_ex2(self):
+ self.assertEqual(countcommon(["perl", "raku", "python"], ["python", "java"]), 1, 'example 2')
+
+ def test_ex3(self):
+ self.assertEqual(countcommon(["guest", "contribution"], ["fun", "weekly", "challenge"]), 0, 'example 3')
+
+unittest.main()
diff --git a/challenge-308/roger-bell-west/python/ch-2.py b/challenge-308/roger-bell-west/python/ch-2.py
new file mode 100755
index 0000000000..5ebb9fe738
--- /dev/null
+++ b/challenge-308/roger-bell-west/python/ch-2.py
@@ -0,0 +1,19 @@
+#! /usr/bin/python3
+
+def decodexor(a, init):
+ out = [init]
+ for v in a:
+ out.append(out[-1] ^ v)
+ return out
+
+import unittest
+
+class TestDecodexor(unittest.TestCase):
+
+ def test_ex1(self):
+ self.assertEqual(decodexor([1, 2, 3], 1), [1, 0, 2, 1], 'example 1')
+
+ def test_ex2(self):
+ self.assertEqual(decodexor([6, 2, 7, 3], 4), [4, 2, 0, 7, 4], 'example 2')
+
+unittest.main()
diff --git a/challenge-308/roger-bell-west/raku/ch-1.p6 b/challenge-308/roger-bell-west/raku/ch-1.p6
new file mode 100755
index 0000000000..3cea509b34
--- /dev/null
+++ b/challenge-308/roger-bell-west/raku/ch-1.p6
@@ -0,0 +1,15 @@
+#! /usr/bin/raku
+
+use Test;
+
+plan 3;
+
+is(countcommon(['perl', 'weekly', 'challenge'], ['raku', 'weekly', 'challenge']), 2, 'example 1');
+is(countcommon(['perl', 'raku', 'python'], ['python', 'java']), 1, 'example 2');
+is(countcommon(['guest', 'contribution'], ['fun', 'weekly', 'challenge']), 0, 'example 3');
+
+sub countcommon(@a, @b) {
+ my %aa = set(@a);
+ my %bb = set(@b);
+ (%aa (&) %bb).elems;
+}
diff --git a/challenge-308/roger-bell-west/raku/ch-2.p6 b/challenge-308/roger-bell-west/raku/ch-2.p6
new file mode 100755
index 0000000000..d6d6d0cf5a
--- /dev/null
+++ b/challenge-308/roger-bell-west/raku/ch-2.p6
@@ -0,0 +1,16 @@
+#! /usr/bin/raku
+
+use Test;
+
+plan 2;
+
+is-deeply(decodexor([1, 2, 3], 1), [1, 0, 2, 1], 'example 1');
+is-deeply(decodexor([6, 2, 7, 3], 4), [4, 2, 0, 7, 4], 'example 2');
+
+sub decodexor(@a, $init) {
+ my @out = [$init];
+ for @a -> $v {
+ @out.push(@out[*-1] +^ $v);
+ }
+ @out;
+}
diff --git a/challenge-308/roger-bell-west/ruby/ch-1.rb b/challenge-308/roger-bell-west/ruby/ch-1.rb
new file mode 100755
index 0000000000..9ce78fc6f9
--- /dev/null
+++ b/challenge-308/roger-bell-west/ruby/ch-1.rb
@@ -0,0 +1,27 @@
+#! /usr/bin/ruby
+
+require 'set'
+
+def countcommon(a, b)
+ aa = Set.new(a)
+ bb = Set.new(b)
+ (aa & bb).length
+end
+
+require 'test/unit'
+
+class TestCountcommon < Test::Unit::TestCase
+
+ def test_ex1
+ assert_equal(2, countcommon(['perl', 'weekly', 'challenge'], ['raku', 'weekly', 'challenge']))
+ end
+
+ def test_ex2
+ assert_equal(1, countcommon(['perl', 'raku', 'python'], ['python', 'java']))
+ end
+
+ def test_ex3
+ assert_equal(0, countcommon(['guest', 'contribution'], ['fun', 'weekly', 'challenge']))
+ end
+
+end
diff --git a/challenge-308/roger-bell-west/ruby/ch-2.rb b/challenge-308/roger-bell-west/ruby/ch-2.rb
new file mode 100755
index 0000000000..6306525136
--- /dev/null
+++ b/challenge-308/roger-bell-west/ruby/ch-2.rb
@@ -0,0 +1,23 @@
+#! /usr/bin/ruby
+
+def decodexor(a, init)
+ out = [ init ]
+ a.each do |v|
+ out.push(out[-1] ^ v)
+ end
+ out
+end
+
+require 'test/unit'
+
+class TestDecodexor < Test::Unit::TestCase
+
+ def test_ex1
+ assert_equal([1, 0, 2, 1], decodexor([1, 2, 3], 1))
+ end
+
+ def test_ex2
+ assert_equal([4, 2, 0, 7, 4], decodexor([6, 2, 7, 3], 4))
+ end
+
+end
diff --git a/challenge-308/roger-bell-west/rust/ch-1.rs b/challenge-308/roger-bell-west/rust/ch-1.rs
new file mode 100755
index 0000000000..33fb782564
--- /dev/null
+++ b/challenge-308/roger-bell-west/rust/ch-1.rs
@@ -0,0 +1,26 @@
+#! /bin/sh
+//usr/bin/env rustc --test $0 -o ${0}x && ./${0}x --nocapture; rm -f ${0}x ; exit
+
+use std::collections::HashSet;
+use std::iter::FromIterator;
+
+#[test]
+fn test_ex1() {
+ assert_eq!(countcommon(vec!["perl", "weekly", "challenge"], vec!["raku", "weekly", "challenge"]), 2);
+}
+
+#[test]
+fn test_ex2() {
+ assert_eq!(countcommon(vec!["perl", "raku", "python"], vec!["python", "java"]), 1);
+}
+
+#[test]
+fn test_ex3() {
+ assert_eq!(countcommon(vec!["guest", "contribution"], vec!["fun", "weekly", "challenge"]), 0);
+}
+
+fn countcommon(a: Vec<&str>, b: Vec<&str>) -> usize {
+ let aa: HashSet<&str> = HashSet::from_iter(a.into_iter());
+ let bb: HashSet<&str> = HashSet::from_iter(b.into_iter());
+ aa.intersection(&bb).count()
+}
diff --git a/challenge-308/roger-bell-west/rust/ch-2.rs b/challenge-308/roger-bell-west/rust/ch-2.rs
new file mode 100755
index 0000000000..9aa11720e2
--- /dev/null
+++ b/challenge-308/roger-bell-west/rust/ch-2.rs
@@ -0,0 +1,20 @@
+#! /bin/sh
+//usr/bin/env rustc --test $0 -o ${0}x && ./${0}x --nocapture; rm -f ${0}x ; exit
+
+#[test]
+fn test_ex1() {
+ assert_eq!(decodexor(vec![1, 2, 3], 1), vec![1, 0, 2, 1]);
+}
+
+#[test]
+fn test_ex2() {
+ assert_eq!(decodexor(vec![6, 2, 7, 3], 4), vec![4, 2, 0, 7, 4]);
+}
+
+fn decodexor(a: Vec<u32>, init: u32) -> Vec<u32> {
+ let mut out = vec![init];
+ for v in a {
+ out.push(out[out.len() - 1] ^ v);
+ }
+ out
+}
diff --git a/challenge-308/roger-bell-west/scala/ch-1.scala b/challenge-308/roger-bell-west/scala/ch-1.scala
new file mode 100644
index 0000000000..b3ab361288
--- /dev/null
+++ b/challenge-308/roger-bell-west/scala/ch-1.scala
@@ -0,0 +1,29 @@
+
+object Countcommon {
+ def countcommon(a: List[String], b: List[String]): Int = {
+ val aa = a.toSet
+ val bb = b.toSet
+ return aa.intersect(bb).toList.size
+ }
+ def main(args: Array[String]) {
+ if (countcommon(List("perl", "weekly", "challenge"), List("raku", "weekly", "challenge")) == 2) {
+ print("Pass")
+ } else {
+ print("Fail")
+ }
+ print(" ")
+ if (countcommon(List("perl", "raku", "python"), List("python", "java")) == 1) {
+ print("Pass")
+ } else {
+ print("Fail")
+ }
+ print(" ")
+ if (countcommon(List("guest", "contribution"), List("fun", "weekly", "challenge")) == 0) {
+ print("Pass")
+ } else {
+ print("Fail")
+ }
+ println("")
+
+ }
+} \ No newline at end of file
diff --git a/challenge-308/roger-bell-west/scala/ch-2.scala b/challenge-308/roger-bell-west/scala/ch-2.scala
new file mode 100644
index 0000000000..67b574aabf
--- /dev/null
+++ b/challenge-308/roger-bell-west/scala/ch-2.scala
@@ -0,0 +1,27 @@
+import scala.collection.mutable.ListBuffer
+
+object Decodexor {
+ def decodexor(a: List[Int], nit: Int): List[Int] = {
+ var out = new ListBuffer[Int]
+ out += nit
+ for (v <- a) {
+ out += (out(out.size - 1) ^ v)
+ }
+ return out.toList
+ }
+ def main(args: Array[String]) {
+ if (decodexor(List(1, 2, 3), 1) == List(1, 0, 2, 1)) {
+ print("Pass")
+ } else {
+ print("Fail")
+ }
+ print(" ")
+ if (decodexor(List(6, 2, 7, 3), 4) == List(4, 2, 0, 7, 4)) {
+ print("Pass")
+ } else {
+ print("Fail")
+ }
+ println("")
+
+ }
+} \ No newline at end of file
diff --git a/challenge-308/roger-bell-west/tests.json b/challenge-308/roger-bell-west/tests.json
new file mode 100644
index 0000000000..c6d5a7228c
--- /dev/null
+++ b/challenge-308/roger-bell-west/tests.json
@@ -0,0 +1,48 @@
+{
+ "ch-1" : [
+ {
+ "function" : "countcommon",
+ "multiarg" : true,
+ "arguments" : [
+ [ "perl", "weekly", "challenge" ],
+ [ "raku", "weekly", "challenge" ]
+ ],
+ "result" : 2
+ },
+ {
+ "multiarg" : true,
+ "arguments" : [
+ [ "perl", "raku", "python" ],
+ [ "python", "java" ]
+ ],
+ "result" : 1
+ },
+ {
+ "multiarg" : true,
+ "arguments" : [
+ [ "guest", "contribution" ],
+ [ "fun", "weekly", "challenge" ]
+ ],
+ "result" : 0
+ }
+ ],
+ "ch-2" : [
+ {
+ "function" : "decodexor",
+ "multiarg" : true,
+ "arguments" : [
+ [ 1, 2, 3 ],
+ 1
+ ],
+ "result" : [ 1, 0, 2, 1 ]
+ },
+ {
+ "multiarg" : true,
+ "arguments" : [
+ [ 6, 2, 7, 3 ],
+ 4
+ ],
+ "result" : [ 4, 2, 0, 7, 4 ]
+ }
+ ]
+}