aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMohammad S Anwar <Mohammad.Anwar@yahoo.com>2022-01-18 18:34:56 +0000
committerGitHub <noreply@github.com>2022-01-18 18:34:56 +0000
commit096598756e1d0c4165e6557f58aa44cf59b25c48 (patch)
treebc9555e17cea03b19fc500c5ca5c4d872bb6efc5
parentedbffb4f99af5c4e9a140cc088cf95ae641594ca (diff)
parente97894899dc9450f5f5928e6a6d6bd0d3db2a304 (diff)
downloadperlweeklychallenge-club-096598756e1d0c4165e6557f58aa44cf59b25c48.tar.gz
perlweeklychallenge-club-096598756e1d0c4165e6557f58aa44cf59b25c48.tar.bz2
perlweeklychallenge-club-096598756e1d0c4165e6557f58aa44cf59b25c48.zip
Merge pull request #5538 from Firedrake/rogerbw-challenge-148
Solutions for challenge #148
-rwxr-xr-xchallenge-148/roger-bell-west/javascript/ch-1.js50
-rwxr-xr-xchallenge-148/roger-bell-west/javascript/ch-2.js69
-rw-r--r--challenge-148/roger-bell-west/kotlin/ch-1.kt21
-rw-r--r--challenge-148/roger-bell-west/kotlin/ch-2.kt40
-rwxr-xr-xchallenge-148/roger-bell-west/lua/ch-1.lua48
-rwxr-xr-xchallenge-148/roger-bell-west/lua/ch-2.lua73
-rwxr-xr-xchallenge-148/roger-bell-west/perl/ch-1.pl22
-rwxr-xr-xchallenge-148/roger-bell-west/perl/ch-2.pl42
-rw-r--r--challenge-148/roger-bell-west/postscript/ch-1.ps45
-rw-r--r--challenge-148/roger-bell-west/postscript/ch-2.ps34
-rwxr-xr-xchallenge-148/roger-bell-west/python/ch-1.py21
-rwxr-xr-xchallenge-148/roger-bell-west/python/ch-2.py38
-rwxr-xr-xchallenge-148/roger-bell-west/raku/ch-1.p620
-rwxr-xr-xchallenge-148/roger-bell-west/raku/ch-2.p640
-rwxr-xr-xchallenge-148/roger-bell-west/ruby/ch-1.rb23
-rwxr-xr-xchallenge-148/roger-bell-west/ruby/ch-2.rb48
-rwxr-xr-xchallenge-148/roger-bell-west/rust/ch-1.rs22
-rwxr-xr-xchallenge-148/roger-bell-west/rust/ch-2.rs48
18 files changed, 704 insertions, 0 deletions
diff --git a/challenge-148/roger-bell-west/javascript/ch-1.js b/challenge-148/roger-bell-west/javascript/ch-1.js
new file mode 100755
index 0000000000..148541fb90
--- /dev/null
+++ b/challenge-148/roger-bell-west/javascript/ch-1.js
@@ -0,0 +1,50 @@
+#! /usr/bin/node
+
+// 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 eban(mx) {
+ let units=[true,false,true,false,true,false,true,false,false,false];
+ let tens=[true,false,false,true,true,true,true,false,false,false,false];
+ let out=[];
+ for (let i = 0; i <= mx; i++) {
+ if (tens[Math.floor(i/10)] &&
+ units[i%10] &&
+ i != 0) {
+ out.push(i);
+ }
+ }
+ return out;
+}
+
+if (deepEqual(eban(100),[2, 4, 6, 30, 32, 34, 36, 40, 42, 44, 46, 50, 52, 54, 56, 60, 62, 64, 66])) {
+ process.stdout.write("Pass");
+} else {
+ process.stdout.write("FAIL");
+}
+process.stdout.write("\n");
+
diff --git a/challenge-148/roger-bell-west/javascript/ch-2.js b/challenge-148/roger-bell-west/javascript/ch-2.js
new file mode 100755
index 0000000000..93d555b5b2
--- /dev/null
+++ b/challenge-148/roger-bell-west/javascript/ch-2.js
@@ -0,0 +1,69 @@
+#! /usr/bin/node
+
+// 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 cardano(ct) {
+ let out=[];
+ let k=0;
+ let cn=0;
+ while (true) {
+ let a=3*k+2;
+ let b2c=(k+1)*(k+1)*(8*k+5);
+ let b=0;
+ let b2=0;
+ let inc=1;
+ while (true) {
+ b++;
+ b2 += inc;
+ inc += 2;
+ if (b2 > b2c) {
+ break;
+ }
+ if (b2c % b2 == 0) {
+ out.push([a,b,b2c/b2]);
+ cn++;
+ if (cn >= ct) {
+ break;
+ }
+ }
+ }
+ if (cn >= ct) {
+ break;
+ }
+ k++;
+ }
+ return out;
+}
+
+if (deepEqual(cardano(5),[[2,1,5],[5,1,52],[5,2,13],[8,1,189],[8,3,21]])) {
+ process.stdout.write("Pass");
+} else {
+ process.stdout.write("FAIL");
+}
+process.stdout.write("\n");
+
diff --git a/challenge-148/roger-bell-west/kotlin/ch-1.kt b/challenge-148/roger-bell-west/kotlin/ch-1.kt
new file mode 100644
index 0000000000..996c0c8afe
--- /dev/null
+++ b/challenge-148/roger-bell-west/kotlin/ch-1.kt
@@ -0,0 +1,21 @@
+fun eban(mx: Int): ArrayList<Int> {
+ val units=listOf(true,false,true,false,true,false,true,false,false,false)
+ val tens=listOf(true,false,false,true,true,true,true,false,false,false,false)
+ var out=ArrayList<Int>()
+ for (i in 0..mx) {
+ if (tens[(i/10).toInt()] &&
+ units[i%10] &&
+ i != 0) {
+ out.add(i)
+ }
+ }
+ return out
+}
+
+fun main() {
+ if (eban(100) == listOf(2, 4, 6, 30, 32, 34, 36, 40, 42, 44, 46, 50, 52, 54, 56, 60, 62, 64, 66)) {
+ println("Pass")
+ } else {
+ println("FAIL")
+ }
+}
diff --git a/challenge-148/roger-bell-west/kotlin/ch-2.kt b/challenge-148/roger-bell-west/kotlin/ch-2.kt
new file mode 100644
index 0000000000..dad69e815e
--- /dev/null
+++ b/challenge-148/roger-bell-west/kotlin/ch-2.kt
@@ -0,0 +1,40 @@
+fun cardano(ct: Int): ArrayList<List<Int>> {
+ var out=ArrayList<List<Int>>()
+ var k=0
+ var cn=0
+ while (true) {
+ val a=3*k+2
+ val b2c=(k+1)*(k+1)*(8*k+5)
+ var b=0
+ var b2=0
+ var inc=1
+ while (true) {
+ b += 1
+ b2 += inc
+ inc += 2
+ if (b2 > b2c) {
+ break
+ }
+ if (b2c % b2 == 0) {
+ out.add(listOf(a,b,b2c/b2))
+ cn += 1
+ if (cn >= ct) {
+ break
+ }
+ }
+ }
+ if (cn >= ct) {
+ break
+ }
+ k += 1
+ }
+ return out
+}
+
+fun main() {
+ if (cardano(5) == listOf(listOf(2,1,5),listOf(5,1,52),listOf(5,2,13),listOf(8,1,189),listOf(8,3,21))) {
+ println("Pass")
+ } else {
+ println("FAIL")
+ }
+}
diff --git a/challenge-148/roger-bell-west/lua/ch-1.lua b/challenge-148/roger-bell-west/lua/ch-1.lua
new file mode 100755
index 0000000000..1dad9e2944
--- /dev/null
+++ b/challenge-148/roger-bell-west/lua/ch-1.lua
@@ -0,0 +1,48 @@
+#! /usr/bin/lua
+
+-- by Michael Anderson at
+-- https://stackoverflow.com/questions/8722620/comparing-two-index-tables-by-index-value-in-lua
+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
+
+ -- Check each key-value pair
+ -- We have to do this both ways in case we miss some.
+ -- TODO: Could probably be smarter and not check those we've
+ -- already checked though!
+ for k1,v1 in pairs(t1) do
+ local v2 = t2[k1]
+ if( not recursive_compare(v1,v2) ) then return false end
+ end
+ for k2,v2 in pairs(t2) do
+ local v1 = t1[k2]
+ if( not recursive_compare(v1,v2) ) then return false end
+ end
+
+ return true
+end
+
+function eban(mx)
+ units={true,false,true,false,true,false,true,false,false,false}
+ tens={true,false,false,true,true,true,true,false,false,false,false}
+ out={}
+ for i = 0,mx do
+ if tens[math.floor(i/10)+1] and units[i%10+1] and i ~= 0 then
+ table.insert(out,i)
+ end
+ end
+ return out
+end
+
+if recursive_compare(eban(100),{2, 4, 6, 30, 32, 34, 36, 40, 42, 44, 46, 50, 52, 54, 56, 60, 62, 64, 66}) then
+ io.write("Pass")
+else
+ io.write("FAIL")
+end
+print("")
diff --git a/challenge-148/roger-bell-west/lua/ch-2.lua b/challenge-148/roger-bell-west/lua/ch-2.lua
new file mode 100755
index 0000000000..19a6a0f1c0
--- /dev/null
+++ b/challenge-148/roger-bell-west/lua/ch-2.lua
@@ -0,0 +1,73 @@
+#! /usr/bin/lua
+
+-- by Michael Anderson at
+-- https://stackoverflow.com/questions/8722620/comparing-two-index-tables-by-index-value-in-lua
+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
+
+ -- Check each key-value pair
+ -- We have to do this both ways in case we miss some.
+ -- TODO: Could probably be smarter and not check those we've
+ -- already checked though!
+ for k1,v1 in pairs(t1) do
+ local v2 = t2[k1]
+ if( not recursive_compare(v1,v2) ) then return false end
+ end
+ for k2,v2 in pairs(t2) do
+ local v1 = t1[k2]
+ if( not recursive_compare(v1,v2) ) then return false end
+ end
+
+ return true
+end
+
+function cardano(ct)
+ local out={}
+ local k=0
+ local cn=0
+ while true do
+ local a=3*k+2
+ local b2c=(k+1)*(k+1)*(8*k+5)
+ local b=0
+ local b2=0
+ local inc=1
+ while true do
+ b = b + 1
+ b2 = b2 + inc
+ inc = inc + 2
+ if b2 > b2c then
+ break
+ end
+ if b2c % b2 == 0 then
+ table.insert(out,{a,b,b2c/b2})
+ cn = cn + 1
+ if cn >= ct then
+ break
+ end
+ end
+ end
+ if cn >= ct then
+ break
+ end
+ k = k + 1
+ end
+ return out
+end
+
+if recursive_compare(cardano(5),{{2,1,5},
+ {5,1,52},
+ {5,2,13},
+ {8,1,189},
+ {8,3,21}}) then
+ io.write("Pass")
+else
+ io.write("FAIL")
+end
+print("")
diff --git a/challenge-148/roger-bell-west/perl/ch-1.pl b/challenge-148/roger-bell-west/perl/ch-1.pl
new file mode 100755
index 0000000000..8102fa739a
--- /dev/null
+++ b/challenge-148/roger-bell-west/perl/ch-1.pl
@@ -0,0 +1,22 @@
+#! /usr/bin/perl
+
+use strict;
+use warnings;
+
+use Test::More tests => 1;
+
+is_deeply(eban(100),[2, 4, 6, 30, 32, 34, 36, 40, 42, 44, 46, 50, 52, 54, 56, 60, 62, 64, 66],
+ 'example 1');
+
+sub eban {
+ my $mx=shift;
+ my @units=(1,0,1,0,1,0,1,0,0,0);
+ my @tens=(1,0,0,1,1,1,1,0,0,0,0);
+ my @out;
+ foreach my $i (0..$mx) {
+ if ($tens[int($i/10)] && $units[$i%10] && $i != 0) {
+ push @out,$i;
+ }
+ }
+ return \@out;
+}
diff --git a/challenge-148/roger-bell-west/perl/ch-2.pl b/challenge-148/roger-bell-west/perl/ch-2.pl
new file mode 100755
index 0000000000..ffe892b327
--- /dev/null
+++ b/challenge-148/roger-bell-west/perl/ch-2.pl
@@ -0,0 +1,42 @@
+#! /usr/bin/perl
+
+use strict;
+use warnings;
+
+use Test::More tests => 1;
+
+is_deeply(cardano(5),[[2,1,5],[5,1,52],[5,2,13],[8,1,189],[8,3,21]],'example 1');
+
+sub cardano {
+ my @out;
+ my $ct=shift;
+ my $k=0;
+ my $cn=0;
+ while (1) {
+ my $a=3*$k+2;
+ my $b2c=($k+1)*($k+1)*(8*$k+5);
+ my $b=0;
+ my $b2=0;
+ my $inc=1;
+ while (1) {
+ $b++;
+ $b2+=$inc;
+ $inc+=2;
+ if ($b2 > $b2c) {
+ last;
+ }
+ if ($b2c % $b2 == 0) {
+ push @out,[$a,$b,$b2c/$b2];
+ $cn++;
+ if ($cn >= $ct) {
+ last;
+ }
+ }
+ }
+ if ($cn >= $ct) {
+ last;
+ }
+ $k++;
+ }
+ return \@out;
+}
diff --git a/challenge-148/roger-bell-west/postscript/ch-1.ps b/challenge-148/roger-bell-west/postscript/ch-1.ps
new file mode 100644
index 0000000000..930397877c
--- /dev/null
+++ b/challenge-148/roger-bell-west/postscript/ch-1.ps
@@ -0,0 +1,45 @@
+%!PS
+
+/aeq {
+ 2 dict begin
+ /a exch def
+ /b exch def
+ a length b length eq {
+ /e true def
+ 0 1 a length 1 sub {
+ dup a exch get
+ exch b exch get ne {
+ /e false def
+ exit
+ } if
+ } for
+ e
+ } {
+ false
+ } ifelse
+ end
+} bind def
+
+/apush { % [a b] c -> [a b c]
+ /t exch def
+ [ exch aload pop t ]
+} bind def
+
+/eban {
+ /units [ true false true false true false true false false false ] def
+ /tens [ true false false true true true true false false false false ] def
+ /out 0 array def
+ 0 exch 1 exch {
+ dup dup dup
+ 10 idiv tens exch get 3 1 roll
+ 10 mod units exch get 3 1 roll
+ 0 ne and and {
+ /out exch out exch apush def
+ } {
+ pop
+ } ifelse
+ } for
+ out
+} bind def
+
+100 eban [ 2 4 6 30 32 34 36 40 42 44 46 50 52 54 56 60 62 64 66 ] aeq { (Pass) } { (FAIL) } ifelse =
diff --git a/challenge-148/roger-bell-west/postscript/ch-2.ps b/challenge-148/roger-bell-west/postscript/ch-2.ps
new file mode 100644
index 0000000000..f4acf9cf22
--- /dev/null
+++ b/challenge-148/roger-bell-west/postscript/ch-2.ps
@@ -0,0 +1,34 @@
+%!PS
+
+/cardano {
+ /cn exch def
+ /k 0 def
+ {
+ /a k 3 mul 2 add def
+ /b2c k 1 add dup mul k 8 mul 5 add mul def
+ /b 0 def
+ /b2 0 def
+ /inc 1 def
+ {
+ /b b 1 add def
+ /b2 b2 inc add def
+ /inc inc 2 add def
+ b2 b2c gt {
+ exit
+ } if
+ b2c b2 mod 0 eq {
+ [ a b b2c b2 idiv ] ==
+ /cn cn 1 sub def
+ cn 0 le {
+ exit
+ } if
+ } if
+ } loop
+ cn 0 le {
+ exit
+ } if
+ /k k 1 add def
+ } loop
+} bind def
+
+5 cardano
diff --git a/challenge-148/roger-bell-west/python/ch-1.py b/challenge-148/roger-bell-west/python/ch-1.py
new file mode 100755
index 0000000000..4df124b07c
--- /dev/null
+++ b/challenge-148/roger-bell-west/python/ch-1.py
@@ -0,0 +1,21 @@
+#! /usr/bin/python3
+
+import unittest
+
+from math import floor
+
+def eban(mx):
+ units=[True,False,True,False,True,False,True,False,False,False]
+ tens=[True,False,False,True,True,True,True,False,False,False,False]
+ out=[]
+ for i in range(mx+1):
+ if tens[floor(i/10)] and units[i%10] and i!=0:
+ out.append(i)
+ return out
+
+class TestEban(unittest.TestCase):
+
+ def test_ex1(self):
+ self.assertEqual(eban(100),[2, 4, 6, 30, 32, 34, 36, 40, 42, 44, 46, 50, 52, 54, 56, 60, 62, 64, 66],'example 1')
+
+unittest.main()
diff --git a/challenge-148/roger-bell-west/python/ch-2.py b/challenge-148/roger-bell-west/python/ch-2.py
new file mode 100755
index 0000000000..828fa4a09a
--- /dev/null
+++ b/challenge-148/roger-bell-west/python/ch-2.py
@@ -0,0 +1,38 @@
+#! /usr/bin/python3
+
+import unittest
+
+from math import floor
+
+def cardano(ct):
+ out=[]
+ k=0
+ cn=0
+ while (True):
+ a=3*k+2
+ b2c=(k+1)*(k+1)*(8*k+5)
+ b=0
+ b2=0
+ inc=1
+ while (True):
+ b += 1
+ b2 += inc
+ inc += 2
+ if b2 > b2c:
+ break
+ if b2c % b2 == 0:
+ out.append([a,b,b2c/b2])
+ cn += 1
+ if cn >= ct:
+ break
+ if cn >= ct:
+ break
+ k += 1
+ return out
+
+class TestCardano(unittest.TestCase):
+
+ def test_ex1(self):
+ self.assertEqual(cardano(5),[[2,1,5],[5,1,52],[5,2,13],[8,1,189],[8,3,21]],'example 1')
+
+unittest.main()
diff --git a/challenge-148/roger-bell-west/raku/ch-1.p6 b/challenge-148/roger-bell-west/raku/ch-1.p6
new file mode 100755
index 0000000000..0381e892e9
--- /dev/null
+++ b/challenge-148/roger-bell-west/raku/ch-1.p6
@@ -0,0 +1,20 @@
+#! /usr/bin/perl6
+
+use Test;
+
+plan 1;
+
+is-deeply(eban(100),[2, 4, 6, 30, 32, 34, 36, 40, 42, 44, 46, 50, 52, 54, 56, 60, 62, 64, 66],
+ 'example 1');
+
+sub eban($mx) {
+ my @units=(True,False,True,False,True,False,True,False,False,False);
+ my @tens=(True,False,False,True,True,True,True,False,False,False,False);
+ my @out;
+ for (0..$mx) -> $i {
+ if (@tens[floor($i/10)] && @units[$i % 10] && $i != 0) {
+ push @out,$i;
+ }
+ }
+ return @out;
+}
diff --git a/challenge-148/roger-bell-west/raku/ch-2.p6 b/challenge-148/roger-bell-west/raku/ch-2.p6
new file mode 100755
index 0000000000..4d3ece69bb
--- /dev/null
+++ b/challenge-148/roger-bell-west/raku/ch-2.p6
@@ -0,0 +1,40 @@
+#! /usr/bin/perl6
+
+use Test;
+
+plan 1;
+
+is-deeply(cardano(5),[[2,1,5],[5,1,52],[5,2,13],[8,1,189],[8,3,21]],'example 1');
+
+sub cardano($ct) {
+ my @out;
+ my $k=0;
+ my $cn=0;
+ while (1) {
+ my $a=3*$k+2;
+ my $b2c=($k+1)*($k+1)*(8*$k+5);
+ my $b=0;
+ my $b2=0;
+ my $inc=1;
+ while (1) {
+ $b++;
+ $b2+=$inc;
+ $inc+=2;
+ if ($b2 > $b2c) {
+ last;
+ }
+ if ($b2c % $b2 == 0) {
+ push @out,[$a,$b,$b2c div $b2];
+ $cn++;
+ if ($cn >= $ct) {
+ last;
+ }
+ }
+ }
+ if ($cn >= $ct) {
+ last;
+ }
+ $k++;
+ }
+ return @out;
+}
diff --git a/challenge-148/roger-bell-west/ruby/ch-1.rb b/challenge-148/roger-bell-west/ruby/ch-1.rb
new file mode 100755
index 0000000000..510f1cec80
--- /dev/null
+++ b/challenge-148/roger-bell-west/ruby/ch-1.rb
@@ -0,0 +1,23 @@
+#! /usr/bin/ruby
+
+require 'test/unit'
+
+def eban(mx)
+ units=[true,false,true,false,true,false,true,false,false,false]
+ tens=[true,false,false,true,true,true,true,false,false,false,false]
+ out=[]
+ 0.upto(mx) do |i|
+ if tens[(i/10).to_i] and units[i%10] and i!=0 then
+ out.push(i)
+ end
+ end
+ return out
+end
+
+class TestEban < Test::Unit::TestCase
+
+ def test_ex1
+ assert_equal([2, 4, 6, 30, 32, 34, 36, 40, 42, 44, 46, 50, 52, 54, 56, 60, 62, 64, 66],eban(100))
+ end
+
+end
diff --git a/challenge-148/roger-bell-west/ruby/ch-2.rb b/challenge-148/roger-bell-west/ruby/ch-2.rb
new file mode 100755
index 0000000000..2cdbcbf608
--- /dev/null
+++ b/challenge-148/roger-bell-west/ruby/ch-2.rb
@@ -0,0 +1,48 @@
+#! /usr/bin/ruby
+
+require 'test/unit'
+
+def cardano(ct)
+ out=[]
+ k=0
+ cn=0
+ while true do
+ a=3*k+2
+ b2c=(k+1)*(k+1)*(8*k+5)
+ b=0
+ b2=0
+ inc=1
+ while true do
+ b += 1
+ b2 += inc
+ inc += 2
+ if b2 > b2c then
+ break
+ end
+ if b2c % b2 == 0 then
+ out.push([a,b,b2c/b2])
+ cn += 1
+ if cn >= ct then
+ break
+ end
+ end
+ end
+ if cn >= ct then
+ break
+ end
+ k += 1
+ end
+ return out
+end
+
+class TestCardano < Test::Unit::TestCase
+
+ def test_ex1
+ assert_equal([[2,1,5],
+ [5,1,52],
+ [5,2,13],
+ [8,1,189],
+ [8,3,21]],cardano(5))
+ end
+
+end
diff --git a/challenge-148/roger-bell-west/rust/ch-1.rs b/challenge-148/roger-bell-west/rust/ch-1.rs
new file mode 100755
index 0000000000..679b6c2c6a
--- /dev/null
+++ b/challenge-148/roger-bell-west/rust/ch-1.rs
@@ -0,0 +1,22 @@
+#! /bin/sh
+//usr/bin/env rustc --test $0 -o ${0}x && ./${0}x; rm -f ${0}x ; exit
+
+#[test]
+fn test_ex1() {
+ assert_eq!(
+ eban(100),
+ vec![2, 4, 6, 30, 32, 34, 36, 40, 42, 44, 46, 50, 52, 54, 56, 60, 62, 64, 66]
+ );
+}
+
+fn eban(mx: usize) -> Vec<usize> {
+ let units=vec![true,false,true,false,true,false,true,false,false,false];
+ let tens=vec![true,false,false,true,true,true,true,false,false,false,false];
+ let mut out=Vec::new();
+ for i in 0..=mx {
+ if tens[i/10] && units[i%10] && i != 0 {
+ out.push(i);
+ }
+ }
+ out
+}
diff --git a/challenge-148/roger-bell-west/rust/ch-2.rs b/challenge-148/roger-bell-west/rust/ch-2.rs
new file mode 100755
index 0000000000..8099e3e8c4
--- /dev/null
+++ b/challenge-148/roger-bell-west/rust/ch-2.rs
@@ -0,0 +1,48 @@
+#! /bin/sh
+//usr/bin/env rustc --test $0 -o ${0}x && ./${0}x; rm -f ${0}x ; exit
+
+#[test]
+fn test_ex1() {
+ assert_eq!(
+ cardano(5),
+ vec![
+ [2,1,5],
+ [5,1,52],
+ [5,2,13],
+ [8,1,189],
+ [8,3,21]
+ ]);
+}
+
+fn cardano(ct: u32) -> Vec<[u32;3]> {
+ let mut out: Vec<[u32;3]>=Vec::new();
+ let mut k=0;
+ let mut cn=0;
+ loop {
+ let a=3*k+2;
+ let b2c=(k+1)*(k+1)*(8*k+5);
+ let mut b=0;
+ let mut b2=0;
+ let mut inc=1;
+ loop {
+ b += 1;
+ b2 += inc;
+ inc += 2;
+ if b2 > b2c {
+ break;
+ }
+ if b2c % b2 == 0 {
+ out.push([a,b,b2c/b2]);
+ cn += 1;
+ if cn >= ct {
+ break;
+ }
+ }
+ }
+ if cn >= ct {
+ break;
+ }
+ k += 1;
+ }
+ out
+}