aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xchallenge-267/roger-bell-west/javascript/ch-1.js34
-rwxr-xr-xchallenge-267/roger-bell-west/javascript/ch-2.js59
-rw-r--r--challenge-267/roger-bell-west/kotlin/ch-1.kt34
-rw-r--r--challenge-267/roger-bell-west/kotlin/ch-2.kt32
-rwxr-xr-xchallenge-267/roger-bell-west/lua/ch-1.lua36
-rwxr-xr-xchallenge-267/roger-bell-west/lua/ch-2.lua72
-rwxr-xr-xchallenge-267/roger-bell-west/perl/ch-1.pl24
-rwxr-xr-xchallenge-267/roger-bell-west/perl/ch-2.pl26
-rw-r--r--challenge-267/roger-bell-west/postscript/ch-1.ps57
-rw-r--r--challenge-267/roger-bell-west/postscript/ch-2.ps123
-rwxr-xr-xchallenge-267/roger-bell-west/python/ch-1.py26
-rwxr-xr-xchallenge-267/roger-bell-west/python/ch-2.py26
-rwxr-xr-xchallenge-267/roger-bell-west/raku/ch-1.p622
-rwxr-xr-xchallenge-267/roger-bell-west/raku/ch-2.p624
-rwxr-xr-xchallenge-267/roger-bell-west/ruby/ch-1.rb32
-rwxr-xr-xchallenge-267/roger-bell-west/ruby/ch-2.rb31
-rwxr-xr-xchallenge-267/roger-bell-west/rust/ch-1.rs30
-rwxr-xr-xchallenge-267/roger-bell-west/rust/ch-2.rs46
-rw-r--r--challenge-267/roger-bell-west/scala/ch-1.scala35
-rw-r--r--challenge-267/roger-bell-west/scala/ch-2.scala32
-rw-r--r--challenge-267/roger-bell-west/tests.yaml93
21 files changed, 894 insertions, 0 deletions
diff --git a/challenge-267/roger-bell-west/javascript/ch-1.js b/challenge-267/roger-bell-west/javascript/ch-1.js
new file mode 100755
index 0000000000..19f56358f4
--- /dev/null
+++ b/challenge-267/roger-bell-west/javascript/ch-1.js
@@ -0,0 +1,34 @@
+#! /usr/bin/node
+
+"use strict"
+
+function productsign(a) {
+ let out = 1;
+ for (let t of a) {
+ if (t < 0) {
+ out = -out;
+ } else if (t == 0) {
+ out = 0;
+ }
+ }
+ return out;
+}
+
+if (productsign([-1, -2, -3, -4, 3, 2, 1]) == 1) {
+ process.stdout.write("Pass");
+} else {
+ process.stdout.write("FAIL");
+}
+process.stdout.write(" ");
+if (productsign([1, 2, 0, -2, -1]) == 0) {
+ process.stdout.write("Pass");
+} else {
+ process.stdout.write("FAIL");
+}
+process.stdout.write(" ");
+if (productsign([-1, -1, 1, -1, 2]) == -1) {
+ process.stdout.write("Pass");
+} else {
+ process.stdout.write("FAIL");
+}
+process.stdout.write("\n");
diff --git a/challenge-267/roger-bell-west/javascript/ch-2.js b/challenge-267/roger-bell-west/javascript/ch-2.js
new file mode 100755
index 0000000000..941618204a
--- /dev/null
+++ b/challenge-267/roger-bell-west/javascript/ch-2.js
@@ -0,0 +1,59 @@
+#! /usr/bin/node
+
+"use strict"
+
+function linecounts (a, w) {
+ let linecount = 1;
+ let linewidth = 0;
+ const asize = 'a'.charCodeAt(0);
+ for (let c of a.split('')) {
+ const wd = w[c.charCodeAt(0) - asize];
+ if (linewidth + wd > 100) {
+ linecount += 1;
+ linewidth = wd;
+ } else {
+ linewidth += wd;
+ }
+ }
+ return [linecount, linewidth];
+}
+
+// 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;
+ }
+}
+
+if (deepEqual(linecounts('abcdefghijklmnopqrstuvwxyz', [10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10]), [3, 60])) {
+ process.stdout.write("Pass");
+} else {
+ process.stdout.write("FAIL");
+}
+process.stdout.write(" ");
+if (deepEqual(linecounts('bbbcccdddaaa', [4, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10]), [2, 4])) {
+ process.stdout.write("Pass");
+} else {
+ process.stdout.write("FAIL");
+}
+process.stdout.write("\n");
diff --git a/challenge-267/roger-bell-west/kotlin/ch-1.kt b/challenge-267/roger-bell-west/kotlin/ch-1.kt
new file mode 100644
index 0000000000..757d089b11
--- /dev/null
+++ b/challenge-267/roger-bell-west/kotlin/ch-1.kt
@@ -0,0 +1,34 @@
+fun productsign(a: List<Int>): Int {
+ var out = 1
+ for (t in a) {
+ if (t < 0) {
+ out = -out
+ } else if (t == 0) {
+ out = 0
+ }
+ }
+ return out
+}
+
+fun main() {
+
+ if (productsign(listOf(-1, -2, -3, -4, 3, 2, 1)) == 1) {
+ print("Pass")
+ } else {
+ print("Fail")
+ }
+ print(" ")
+ if (productsign(listOf(1, 2, 0, -2, -1)) == 0) {
+ print("Pass")
+ } else {
+ print("Fail")
+ }
+ print(" ")
+ if (productsign(listOf(-1, -1, 1, -1, 2)) == -1) {
+ print("Pass")
+ } else {
+ print("Fail")
+ }
+ println("")
+
+}
diff --git a/challenge-267/roger-bell-west/kotlin/ch-2.kt b/challenge-267/roger-bell-west/kotlin/ch-2.kt
new file mode 100644
index 0000000000..b243dcc70e
--- /dev/null
+++ b/challenge-267/roger-bell-west/kotlin/ch-2.kt
@@ -0,0 +1,32 @@
+fun linecounts (a: String, w: List<Int>): List<Int> {
+ var linecount = 1
+ var linewidth = 0
+ val asize = 'a'.code
+ for (c in a.toList()) {
+ val wd = w[c.code - asize]
+ if (linewidth + wd > 100) {
+ linecount += 1
+ linewidth = wd
+ } else {
+ linewidth += wd
+ }
+ }
+ return listOf(linecount, linewidth)
+}
+
+fun main() {
+
+ if (linecounts("abcdefghijklmnopqrstuvwxyz", listOf(10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10)) == listOf(3, 60)) {
+ print("Pass")
+ } else {
+ print("Fail")
+ }
+ print(" ")
+ if (linecounts("bbbcccdddaaa", listOf(4, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10)) == listOf(2, 4)) {
+ print("Pass")
+ } else {
+ print("Fail")
+ }
+ println("")
+
+}
diff --git a/challenge-267/roger-bell-west/lua/ch-1.lua b/challenge-267/roger-bell-west/lua/ch-1.lua
new file mode 100755
index 0000000000..ba920c38a6
--- /dev/null
+++ b/challenge-267/roger-bell-west/lua/ch-1.lua
@@ -0,0 +1,36 @@
+#! /usr/bin/lua
+
+function productsign(a)
+ local out = 1
+ for _, t in ipairs(a) do
+ if t < 0 then
+ out = - out
+ elseif t == 0 then
+ out = 0
+ break
+ end
+ end
+ return out
+end
+
+if productsign({-1, -2, -3, -4, 3, 2, 1}) == 1 then
+ io.write("Pass")
+else
+ io.write("FAIL")
+end
+io.write(" ")
+
+if productsign({1, 2, 0, -2, -1}) == 0 then
+ io.write("Pass")
+else
+ io.write("FAIL")
+end
+io.write(" ")
+
+if productsign({-1, -1, 1, -1, 2}) == -1 then
+ io.write("Pass")
+else
+ io.write("FAIL")
+end
+print("")
+
diff --git a/challenge-267/roger-bell-west/lua/ch-2.lua b/challenge-267/roger-bell-west/lua/ch-2.lua
new file mode 100755
index 0000000000..ab9316b8f0
--- /dev/null
+++ b/challenge-267/roger-bell-west/lua/ch-2.lua
@@ -0,0 +1,72 @@
+#! /usr/bin/lua
+
+function split(t)
+ local cl = {}
+ string.gsub(t,
+ "(.)",
+ function(c)
+ table.insert(cl, c)
+ end
+ )
+ return cl
+end
+
+function linecounts(a, w)
+ local linecount = 1
+ local linewidth = 0
+ local asize = string.byte("a") - 1
+ for _, c in ipairs(split(a)) do
+ local wd = w[string.byte(c) - asize]
+ if linewidth + wd > 100 then
+ linecount = linecount + 1
+ linewidth = wd
+ else
+ linewidth = linewidth + wd
+ end
+ end
+ return {linecount, linewidth}
+end
+
+-- 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
+
+if recursive_compare(linecounts("abcdefghijklmnopqrstuvwxyz", {10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10}), {3, 60}) then
+ io.write("Pass")
+else
+ io.write("FAIL")
+end
+io.write(" ")
+
+if recursive_compare(linecounts("bbbcccdddaaa", {4, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10}), {2, 4}) then
+ io.write("Pass")
+else
+ io.write("FAIL")
+end
+print("")
+
diff --git a/challenge-267/roger-bell-west/perl/ch-1.pl b/challenge-267/roger-bell-west/perl/ch-1.pl
new file mode 100755
index 0000000000..653445c648
--- /dev/null
+++ b/challenge-267/roger-bell-west/perl/ch-1.pl
@@ -0,0 +1,24 @@
+#! /usr/bin/perl
+
+use strict;
+use warnings;
+use experimental 'signatures';
+
+use Test::More tests => 3;
+
+is(productsign([-1, -2, -3, -4, 3, 2, 1]), 1, 'example 1');
+is(productsign([1, 2, 0, -2, -1]), 0, 'example 2');
+is(productsign([-1, -1, 1, -1, 2]), -1, 'example 3');
+
+sub productsign($a) {
+ my $out = 1;
+ foreach my $t (@{$a}) {
+ if ($t < 0) {
+ $out = -$out;
+ } elsif ($t == 0) {
+ $out = 0;
+ last;
+ }
+ }
+ return $out;
+}
diff --git a/challenge-267/roger-bell-west/perl/ch-2.pl b/challenge-267/roger-bell-west/perl/ch-2.pl
new file mode 100755
index 0000000000..82f8f8ecf3
--- /dev/null
+++ b/challenge-267/roger-bell-west/perl/ch-2.pl
@@ -0,0 +1,26 @@
+#! /usr/bin/perl
+
+use strict;
+use warnings;
+use experimental 'signatures';
+
+use Test::More tests => 2;
+
+is_deeply(linecounts('abcdefghijklmnopqrstuvwxyz', [10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10]), [3, 60], 'example 1');
+is_deeply(linecounts('bbbcccdddaaa', [4, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10]), [2, 4], 'example 2');
+
+sub linecounts($a, $w) {
+ my $linecount = 1;
+ my $linewidth = 0;
+ my $asize = ord('a');
+ foreach my $c (split '',$a) {
+ my $wd = $w->[ord($c) - $asize];
+ if ($linewidth + $wd > 100) {
+ $linecount++;
+ $linewidth = $wd;
+ } else {
+ $linewidth += $wd;
+ }
+ }
+ return [$linecount, $linewidth];
+}
diff --git a/challenge-267/roger-bell-west/postscript/ch-1.ps b/challenge-267/roger-bell-west/postscript/ch-1.ps
new file mode 100644
index 0000000000..c39bb1c895
--- /dev/null
+++ b/challenge-267/roger-bell-west/postscript/ch-1.ps
@@ -0,0 +1,57 @@
+%!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.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
+
+/test.start {
+ print (:) print
+ /test.pass 0 def
+ /test.count 0 def
+} bind def
+
+
+% end included library code
+
+/productsign {
+ 1 exch
+ {
+ dup 0 lt {
+ pop neg
+ } {
+ 0 eq {
+ pop 0
+ exit
+ } if
+ } ifelse
+ } forall
+} bind def
+
+(productsign) test.start
+[-1 -2 -3 -4 3 2 1] productsign 1 eq test
+[1 2 0 -2 -1] productsign 0 eq test
+[-1 -1 1 -1 2] productsign -1 eq test
+test.end
diff --git a/challenge-267/roger-bell-west/postscript/ch-2.ps b/challenge-267/roger-bell-west/postscript/ch-2.ps
new file mode 100644
index 0000000000..3ae321d5b8
--- /dev/null
+++ b/challenge-267/roger-bell-west/postscript/ch-2.ps
@@ -0,0 +1,123 @@
+%!PS
+
+% begin included library code
+% see https://codeberg.org/Firedrake/postscript-libraries/
+/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
+
+/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
+
+/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
+
+/test.start {
+ print (:) print
+ /test.pass 0 def
+ /test.count 0 def
+} bind def
+
+/s2a {
+ [ exch { } forall ]
+} bind def
+
+
+% end included library code
+
+/linecounts {
+ 0 dict begin
+ /w exch def
+ /linecount 1 def
+ /linewidth 0 def
+ /asize 97 def
+ s2a {
+ /wd exch asize sub w exch get def
+ linewidth wd add 100 gt {
+ /linecount linecount 1 add def
+ /linewidth wd def
+ } {
+ /linewidth linewidth wd add def
+ } ifelse
+ } forall
+ [ linecount linewidth ]
+ end
+} bind def
+
+(linecounts) test.start
+(abcdefghijklmnopqrstuvwxyz) [10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10] linecounts [3 60] deepeq test
+(bbbcccdddaaa) [4 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10] linecounts [2 4] deepeq test
+test.end
diff --git a/challenge-267/roger-bell-west/python/ch-1.py b/challenge-267/roger-bell-west/python/ch-1.py
new file mode 100755
index 0000000000..bb9313a2c6
--- /dev/null
+++ b/challenge-267/roger-bell-west/python/ch-1.py
@@ -0,0 +1,26 @@
+#! /usr/bin/python3
+
+def productsign(a):
+ out = 1
+ for t in a:
+ if t < 0:
+ out = -out
+ elif t == 0:
+ out = 0
+ break
+ return out
+
+import unittest
+
+class TestProductsign(unittest.TestCase):
+
+ def test_ex1(self):
+ self.assertEqual(productsign([-1, -2, -3, -4, 3, 2, 1]), 1, 'example 1')
+
+ def test_ex2(self):
+ self.assertEqual(productsign([1, 2, 0, -2, -1]), 0, 'example 2')
+
+ def test_ex3(self):
+ self.assertEqual(productsign([-1, -1, 1, -1, 2]), -1, 'example 3')
+
+unittest.main()
diff --git a/challenge-267/roger-bell-west/python/ch-2.py b/challenge-267/roger-bell-west/python/ch-2.py
new file mode 100755
index 0000000000..2b8438d195
--- /dev/null
+++ b/challenge-267/roger-bell-west/python/ch-2.py
@@ -0,0 +1,26 @@
+#! /usr/bin/python3
+
+def linecounts(a, w):
+ linecount = 1
+ linewidth = 0
+ asize = ord('a')
+ for c in a:
+ wd = w[ord(c) - asize]
+ if linewidth + wd > 100:
+ linecount += 1
+ linewidth = wd
+ else:
+ linewidth += wd
+ return [linecount, linewidth]
+
+import unittest
+
+class TestLinecounts(unittest.TestCase):
+
+ def test_ex1(self):
+ self.assertEqual(linecounts("abcdefghijklmnopqrstuvwxyz", [10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10]), [3, 60], 'example 1')
+
+ def test_ex2(self):
+ self.assertEqual(linecounts("bbbcccdddaaa", [4, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10]), [2, 4], 'example 2')
+
+unittest.main()
diff --git a/challenge-267/roger-bell-west/raku/ch-1.p6 b/challenge-267/roger-bell-west/raku/ch-1.p6
new file mode 100755
index 0000000000..cf5f438944
--- /dev/null
+++ b/challenge-267/roger-bell-west/raku/ch-1.p6
@@ -0,0 +1,22 @@
+#! /usr/bin/raku
+
+use Test;
+
+plan 3;
+
+is(productsign([-1, -2, -3, -4, 3, 2, 1]), 1, 'example 1');
+is(productsign([1, 2, 0, -2, -1]), 0, 'example 2');
+is(productsign([-1, -1, 1, -1, 2]), -1, 'example 3');
+
+sub productsign(@a) {
+ my $out = 1;
+ for @a -> $t {
+ if ($t < 0) {
+ $out = -$out;
+ } elsif ($t == 0) {
+ $out = 0;
+ last;
+ }
+ }
+ return $out;
+}
diff --git a/challenge-267/roger-bell-west/raku/ch-2.p6 b/challenge-267/roger-bell-west/raku/ch-2.p6
new file mode 100755
index 0000000000..2bfd17f67e
--- /dev/null
+++ b/challenge-267/roger-bell-west/raku/ch-2.p6
@@ -0,0 +1,24 @@
+#! /usr/bin/raku
+
+use Test;
+
+plan 2;
+
+is-deeply(linecounts('abcdefghijklmnopqrstuvwxyz', [10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10]), [3, 60], 'example 1');
+is-deeply(linecounts('bbbcccdddaaa', [4, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10]), [2, 4], 'example 2');
+
+sub linecounts($a, @w) {
+ my $linecount = 1;
+ my $linewidth = 0;
+ my $asize = ord('a');
+ for $a.comb -> $c {
+ my $wd = @w[ord($c) - $asize];
+ if ($linewidth + $wd > 100) {
+ $linecount++;
+ $linewidth = $wd;
+ } else {
+ $linewidth += $wd;
+ }
+ }
+ return [$linecount, $linewidth];
+}
diff --git a/challenge-267/roger-bell-west/ruby/ch-1.rb b/challenge-267/roger-bell-west/ruby/ch-1.rb
new file mode 100755
index 0000000000..04b0d8f541
--- /dev/null
+++ b/challenge-267/roger-bell-west/ruby/ch-1.rb
@@ -0,0 +1,32 @@
+#! /usr/bin/ruby
+
+def productsign(a)
+ out = 1
+ a.each do |t|
+ if t < 0 then
+ out = -out
+ elsif t == 0
+ out = 0
+ break
+ end
+ end
+ return out
+end
+
+require 'test/unit'
+
+class TestProductsign < Test::Unit::TestCase
+
+ def test_ex1
+ assert_equal(1, productsign([-1, -2, -3, -4, 3, 2, 1]))
+ end
+
+ def test_ex2
+ assert_equal(0, productsign([1, 2, 0, -2, -1]))
+ end
+
+ def test_ex3
+ assert_equal(-1, productsign([-1, -1, 1, -1, 2]))
+ end
+
+end
diff --git a/challenge-267/roger-bell-west/ruby/ch-2.rb b/challenge-267/roger-bell-west/ruby/ch-2.rb
new file mode 100755
index 0000000000..86d7fac102
--- /dev/null
+++ b/challenge-267/roger-bell-west/ruby/ch-2.rb
@@ -0,0 +1,31 @@
+#! /usr/bin/ruby
+
+def linecounts(a, w)
+ linecount = 1
+ linewidth = 0
+ asize = 'a'.ord()
+ a.split('').each do |c|
+ wd = w[c.ord() - asize]
+ if linewidth + wd > 100 then
+ linecount += 1
+ linewidth = wd
+ else
+ linewidth += wd;
+ end
+ end
+ return [linecount, linewidth]
+end
+
+require 'test/unit'
+
+class TestLinecounts < Test::Unit::TestCase
+
+ def test_ex1
+ assert_equal([3, 60], linecounts('abcdefghijklmnopqrstuvwxyz', [10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10]))
+ end
+
+ def test_ex2
+ assert_equal([2, 4], linecounts('bbbcccdddaaa', [4, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10]))
+ end
+
+end
diff --git a/challenge-267/roger-bell-west/rust/ch-1.rs b/challenge-267/roger-bell-west/rust/ch-1.rs
new file mode 100755
index 0000000000..54aafb43ba
--- /dev/null
+++ b/challenge-267/roger-bell-west/rust/ch-1.rs
@@ -0,0 +1,30 @@
+#! /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!(productsign(vec![-1, -2, -3, -4, 3, 2, 1]), 1);
+}
+
+#[test]
+fn test_ex2() {
+ assert_eq!(productsign(vec![1, 2, 0, -2, -1]), 0);
+}
+
+#[test]
+fn test_ex3() {
+ assert_eq!(productsign(vec![-1, -1, 1, -1, 2]), -1);
+}
+
+fn productsign(a: Vec<i32>) -> i8 {
+ let mut out = 1;
+ for t in a {
+ if t < 0 {
+ out = -out;
+ } else if t == 0 {
+ out = 0;
+ break;
+ }
+ }
+ out
+}
diff --git a/challenge-267/roger-bell-west/rust/ch-2.rs b/challenge-267/roger-bell-west/rust/ch-2.rs
new file mode 100755
index 0000000000..cc260198b3
--- /dev/null
+++ b/challenge-267/roger-bell-west/rust/ch-2.rs
@@ -0,0 +1,46 @@
+#! /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!(
+ linecounts(
+ "abcdefghijklmnopqrstuvwxyz",
+ vec![
+ 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10,
+ 10, 10, 10, 10, 10, 10, 10, 10, 10, 10
+ ]
+ ),
+ vec![3, 60]
+ );
+}
+
+#[test]
+fn test_ex2() {
+ assert_eq!(
+ linecounts(
+ "bbbcccdddaaa",
+ vec![
+ 4, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10,
+ 10, 10, 10, 10, 10, 10, 10, 10, 10, 10
+ ]
+ ),
+ vec![2, 4]
+ );
+}
+
+fn linecounts(a: &str, w: Vec<u32>) -> Vec<u32> {
+ let mut linecount = 1;
+ let mut linewidth = 0;
+ let asize = 'a' as usize;
+ for c in a.chars() {
+ let wd = w[c as usize - asize];
+ if linewidth + wd > 100 {
+ linecount += 1;
+ linewidth = wd;
+ } else {
+ linewidth += wd;
+ }
+ }
+ vec![linecount, linewidth]
+}
diff --git a/challenge-267/roger-bell-west/scala/ch-1.scala b/challenge-267/roger-bell-west/scala/ch-1.scala
new file mode 100644
index 0000000000..f90a5713f6
--- /dev/null
+++ b/challenge-267/roger-bell-west/scala/ch-1.scala
@@ -0,0 +1,35 @@
+
+object Productsign {
+ def productsign(a: List[Int]): Int = {
+ var out = 1
+ for (t <- a) {
+ if (t < 0) {
+ out = -out
+ } else if (t == 0) {
+ out = 0
+ }
+ }
+ out
+ }
+ def main(args: Array[String]) {
+ if (productsign(List(-1, -2, -3, -4, 3, 2, 1)) == 1) {
+ print("Pass")
+ } else {
+ print("Fail")
+ }
+ print(" ")
+ if (productsign(List(1, 2, 0, -2, -1)) == 0) {
+ print("Pass")
+ } else {
+ print("Fail")
+ }
+ print(" ")
+ if (productsign(List(-1, -1, 1, -1, 2)) == -1) {
+ print("Pass")
+ } else {
+ print("Fail")
+ }
+ println("")
+
+ }
+}
diff --git a/challenge-267/roger-bell-west/scala/ch-2.scala b/challenge-267/roger-bell-west/scala/ch-2.scala
new file mode 100644
index 0000000000..3c00faebb1
--- /dev/null
+++ b/challenge-267/roger-bell-west/scala/ch-2.scala
@@ -0,0 +1,32 @@
+object Linecounts {
+ def linecounts (a: String, w: List[Int]): List[Int] = {
+ var linecount = 1
+ var linewidth = 0
+ val asize = 'a'.toInt
+ for (c <- a.toList) {
+ val wd = w(c.toInt - asize)
+ if (linewidth + wd > 100) {
+ linecount += 1
+ linewidth = wd
+ } else {
+ linewidth += wd
+ }
+ }
+ List(linecount, linewidth)
+ }
+ def main(args: Array[String]) {
+ if (linecounts("abcdefghijklmnopqrstuvwxyz", List(10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10)) == List(3, 60)) {
+ print("Pass")
+ } else {
+ print("Fail")
+ }
+ print(" ")
+ if (linecounts("bbbcccdddaaa", List(4, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10)) == List(2, 4)) {
+ print("Pass")
+ } else {
+ print("Fail")
+ }
+ println("")
+
+ }
+}
diff --git a/challenge-267/roger-bell-west/tests.yaml b/challenge-267/roger-bell-west/tests.yaml
new file mode 100644
index 0000000000..fac306b6ed
--- /dev/null
+++ b/challenge-267/roger-bell-west/tests.yaml
@@ -0,0 +1,93 @@
+---
+ch-1:
+ - function: productsign
+ arguments:
+ - -1
+ - -2
+ - -3
+ - -4
+ - 3
+ - 2
+ - 1
+ result: 1
+ - arguments:
+ - 1
+ - 2
+ - 0
+ - -2
+ - -1
+ result: 0
+ - arguments:
+ - -1
+ - -1
+ - 1
+ - -1
+ - 2
+ result: -1
+ch-2:
+ - function: linecounts
+ multiarg: 1
+ arguments:
+ - abcdefghijklmnopqrstuvwxyz
+ - - 10
+ - 10
+ - 10
+ - 10
+ - 10
+ - 10
+ - 10
+ - 10
+ - 10
+ - 10
+ - 10
+ - 10
+ - 10
+ - 10
+ - 10
+ - 10
+ - 10
+ - 10
+ - 10
+ - 10
+ - 10
+ - 10
+ - 10
+ - 10
+ - 10
+ - 10
+ result:
+ - 3
+ - 60
+ - function: linecounts
+ multiarg: 1
+ arguments:
+ - bbbcccdddaaa
+ - - 4
+ - 10
+ - 10
+ - 10
+ - 10
+ - 10
+ - 10
+ - 10
+ - 10
+ - 10
+ - 10
+ - 10
+ - 10
+ - 10
+ - 10
+ - 10
+ - 10
+ - 10
+ - 10
+ - 10
+ - 10
+ - 10
+ - 10
+ - 10
+ - 10
+ - 10
+ result:
+ - 2
+ - 4