aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMohammad S Anwar <Mohammad.Anwar@yahoo.com>2022-01-25 19:45:20 +0000
committerGitHub <noreply@github.com>2022-01-25 19:45:20 +0000
commit4b507f36f46f3b72ebf6402675769c730d0f7760 (patch)
treeb6de70a0a50770217bc672790b15e93cd2f75f53
parent64a9cce1125c557c227247c623c0d6be102d10f7 (diff)
parent1a8bb9ad40d6b178c661a40613383768123e3787 (diff)
downloadperlweeklychallenge-club-4b507f36f46f3b72ebf6402675769c730d0f7760.tar.gz
perlweeklychallenge-club-4b507f36f46f3b72ebf6402675769c730d0f7760.tar.bz2
perlweeklychallenge-club-4b507f36f46f3b72ebf6402675769c730d0f7760.zip
Merge pull request #5561 from Firedrake/rogerbw-challenge-149
Solutions for challenge #149
-rwxr-xr-xchallenge-149/roger-bell-west/javascript/ch-1.js76
-rwxr-xr-xchallenge-149/roger-bell-west/javascript/ch-2.js60
-rw-r--r--challenge-149/roger-bell-west/kotlin/ch-1.kt51
-rw-r--r--challenge-149/roger-bell-west/kotlin/ch-2.kt61
-rwxr-xr-xchallenge-149/roger-bell-west/lua/ch-1.lua77
-rwxr-xr-xchallenge-149/roger-bell-west/lua/ch-2.lua61
-rwxr-xr-xchallenge-149/roger-bell-west/perl/ch-1.pl35
-rwxr-xr-xchallenge-149/roger-bell-west/perl/ch-2.pl42
-rw-r--r--challenge-149/roger-bell-west/postscript/ch-1.ps80
-rw-r--r--challenge-149/roger-bell-west/postscript/ch-2.ps63
-rwxr-xr-xchallenge-149/roger-bell-west/python/ch-1.py39
-rwxr-xr-xchallenge-149/roger-bell-west/python/ch-2.py45
-rwxr-xr-xchallenge-149/roger-bell-west/raku/ch-1.p633
-rwxr-xr-xchallenge-149/roger-bell-west/raku/ch-2.p641
-rwxr-xr-xchallenge-149/roger-bell-west/ruby/ch-1.rb47
-rwxr-xr-xchallenge-149/roger-bell-west/ruby/ch-2.rb53
-rwxr-xr-xchallenge-149/roger-bell-west/rust/ch-1.rs45
-rwxr-xr-xchallenge-149/roger-bell-west/rust/ch-2.rs54
18 files changed, 963 insertions, 0 deletions
diff --git a/challenge-149/roger-bell-west/javascript/ch-1.js b/challenge-149/roger-bell-west/javascript/ch-1.js
new file mode 100755
index 0000000000..74132cfa72
--- /dev/null
+++ b/challenge-149/roger-bell-west/javascript/ch-1.js
@@ -0,0 +1,76 @@
+#! /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 fds(n) {
+ let out=[];
+ let f=[1,0];
+ let ft=new Set(f);
+ let k=0;
+ while (out.length < n) {
+ let ds=0;
+ let j=k;
+ while (j > 0) {
+ ds += j % 10;
+ j=Math.floor(j/10);
+ }
+ while (f[0] < ds) {
+ let t=f[1]+f[0];
+ f[1]=f[0];
+ f[0]=t;
+ ft.add(f[0]);
+ }
+ if (ft.has(ds)) {
+ out.push(k);
+ }
+ k++;
+ }
+ return out;
+}
+
+if (deepEqual(fds(8),[0, 1, 2, 3, 5, 8, 10, 11])) {
+ process.stdout.write("Pass");
+} else {
+ process.stdout.write("FAIL");
+}
+process.stdout.write(" ");
+
+if (deepEqual(fds(20),[0, 1, 2, 3, 5, 8, 10, 11, 12, 14, 17, 20, 21, 23, 26, 30, 32, 35, 41, 44])) {
+ process.stdout.write("Pass");
+} else {
+ process.stdout.write("FAIL");
+}
+process.stdout.write(" ");
+
+if (deepEqual(fds(61),[0, 1, 2, 3, 5, 8, 10, 11, 12, 14, 17, 20, 21, 23, 26, 30, 32, 35, 41, 44, 49, 50, 53, 58, 62, 67, 71, 76, 80, 85, 94, 100, 101, 102, 104, 107, 110, 111, 113, 116, 120, 122, 125, 131, 134, 139, 140, 143, 148, 152, 157, 161, 166, 170, 175, 184, 193, 200, 201, 203, 206])) {
+ process.stdout.write("Pass");
+} else {
+ process.stdout.write("FAIL");
+}
+process.stdout.write("\n");
+
diff --git a/challenge-149/roger-bell-west/javascript/ch-2.js b/challenge-149/roger-bell-west/javascript/ch-2.js
new file mode 100755
index 0000000000..999fbcf321
--- /dev/null
+++ b/challenge-149/roger-bell-west/javascript/ch-2.js
@@ -0,0 +1,60 @@
+#! /usr/bin/node
+
+function ls(base) {
+ let max=0;
+ for(let i=base; i>0; i--) {
+ max *= base;
+ max += i;
+ }
+ let t=Math.floor(Math.sqrt(max));
+ let digits="0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
+ while (true) {
+ let s=t*t;
+ let v=true;
+ let c=Array.from(Array(base),_ => 0);
+ let dg=[];
+ while (s > 0) {
+ let d=s % base;
+ c[d]++;
+ if (c[d] > 1) {
+ v=false;
+ break;
+ }
+ s=Math.floor(s/base);
+ dg.unshift(digits[d]);
+ }
+ if (v) {
+ return dg.join("");
+ }
+ t--;
+ }
+}
+
+if (ls(2) == "1") {
+ process.stdout.write("Pass");
+} else {
+ process.stdout.write("FAIL");
+}
+process.stdout.write(" ");
+
+if (ls(4) == "3201") {
+ process.stdout.write("Pass");
+} else {
+ process.stdout.write("FAIL");
+}
+process.stdout.write(" ");
+
+if (ls(10) == "9814072356") {
+ process.stdout.write("Pass");
+} else {
+ process.stdout.write("FAIL");
+}
+process.stdout.write(" ");
+
+if (ls(12) == "B8750A649321") {
+ process.stdout.write("Pass");
+} else {
+ process.stdout.write("FAIL");
+}
+process.stdout.write("\n");
+
diff --git a/challenge-149/roger-bell-west/kotlin/ch-1.kt b/challenge-149/roger-bell-west/kotlin/ch-1.kt
new file mode 100644
index 0000000000..526f498dab
--- /dev/null
+++ b/challenge-149/roger-bell-west/kotlin/ch-1.kt
@@ -0,0 +1,51 @@
+fun fds(n: Int): ArrayList<Int> {
+ var o=ArrayList<Int>()
+ var f=arrayOf(1,0)
+ var ft=mutableSetOf<Int>()
+ for (i in f) {
+ ft.add(i)
+ }
+ var k=0
+ while (o.size < n) {
+ var j: Int=k
+ var ds=0
+ while (j > 0) {
+ ds += j % 10
+ j = j/10
+ }
+ while (f[0] < ds) {
+ val t=f[1]+f[0]
+ f[1]=f[0]
+ f[0]=t
+ ft.add(f[0])
+ }
+ if (ft.contains(ds)) {
+ o.add(k)
+ }
+ k += 1
+ }
+ return o
+}
+
+fun main() {
+ if (fds(8) == listOf(0, 1, 2, 3, 5, 8, 10, 11)) {
+ print("Pass")
+ } else {
+ print("FAIL")
+ }
+ print(" ")
+
+ if (fds(20) == listOf(0, 1, 2, 3, 5, 8, 10, 11, 12, 14, 17, 20, 21, 23, 26, 30, 32, 35, 41, 44)) {
+ print("Pass")
+ } else {
+ print("FAIL")
+ }
+ print(" ")
+
+ if (fds(61) == listOf(0, 1, 2, 3, 5, 8, 10, 11, 12, 14, 17, 20, 21, 23, 26, 30, 32, 35, 41, 44, 49, 50, 53, 58, 62, 67, 71, 76, 80, 85, 94, 100, 101, 102, 104, 107, 110, 111, 113, 116, 120, 122, 125, 131, 134, 139, 140, 143, 148, 152, 157, 161, 166, 170, 175, 184, 193, 200, 201, 203, 206)) {
+ print("Pass")
+ } else {
+ print("FAIL")
+ }
+ println("")
+}
diff --git a/challenge-149/roger-bell-west/kotlin/ch-2.kt b/challenge-149/roger-bell-west/kotlin/ch-2.kt
new file mode 100644
index 0000000000..d9c68489af
--- /dev/null
+++ b/challenge-149/roger-bell-west/kotlin/ch-2.kt
@@ -0,0 +1,61 @@
+import kotlin.math.*
+
+fun ls(base: Int): String {
+ var max: Long=0
+ for (i in base-1 downTo 0) {
+ max *= base
+ max += i
+ }
+ var t=sqrt(max.toDouble()).toLong()
+ val digits="0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"
+ while (true) {
+ var s=t*t
+ var v=true
+ var c=IntArray(base) {_ -> 0}
+ var dg: String=""
+ while (s > 0) {
+ val d=(s % base).toInt()
+ c[d] += 1
+ if (c[d] > 1) {
+ v=false
+ break
+ }
+ s /= base
+ dg = digits[d] + dg
+ }
+ if (v) {
+ return dg
+ }
+ t -= 1
+ }
+}
+
+fun main() {
+ if (ls(2) == "1") {
+ print("Pass")
+ } else {
+ print("FAIL")
+ }
+ print(" ")
+
+ if (ls(4) == "3201") {
+ print("Pass")
+ } else {
+ print("FAIL")
+ }
+ print(" ")
+
+ if (ls(10) == "9814072356") {
+ print("Pass")
+ } else {
+ print("FAIL")
+ }
+ print(" ")
+
+ if (ls(12) == "B8750A649321") {
+ print("Pass")
+ } else {
+ print("FAIL")
+ }
+ println("")
+}
diff --git a/challenge-149/roger-bell-west/lua/ch-1.lua b/challenge-149/roger-bell-west/lua/ch-1.lua
new file mode 100755
index 0000000000..a655491e2a
--- /dev/null
+++ b/challenge-149/roger-bell-west/lua/ch-1.lua
@@ -0,0 +1,77 @@
+#! /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 fds(n)
+ out={}
+ f={1,0}
+ ft={}
+ for i,v in ipairs(f) do
+ ft[v]=true
+ end
+ k=0
+ while #out < n do
+ j=k
+ ds=0
+ while j > 0 do
+ ds = ds + j % 10
+ j=math.floor(j/10)
+ end
+ while f[1] < ds do
+ f[1],f[2]=f[1]+f[2],f[1]
+ ft[f[1]]=true
+ end
+ if ft[ds] ~= nil then
+ table.insert(out,k)
+ end
+ k = k + 1
+ end
+ return out
+end
+
+if recursive_compare(fds(8),{0, 1, 2, 3, 5, 8, 10, 11}) then
+ io.write("Pass")
+else
+ io.write("FAIL")
+end
+io.write(" ")
+
+if recursive_compare(fds(20),{0, 1, 2, 3, 5, 8, 10, 11, 12, 14, 17, 20, 21, 23, 26, 30, 32, 35, 41, 44}) then
+ io.write("Pass")
+else
+ io.write("FAIL")
+end
+io.write(" ")
+
+if recursive_compare(fds(61),{0, 1, 2, 3, 5, 8, 10, 11, 12, 14, 17, 20, 21, 23, 26, 30, 32, 35, 41, 44, 49, 50, 53, 58, 62, 67, 71, 76, 80, 85, 94, 100, 101, 102, 104, 107, 110, 111, 113, 116, 120, 122, 125, 131, 134, 139, 140, 143, 148, 152, 157, 161, 166, 170, 175, 184, 193, 200, 201, 203, 206}) then
+ io.write("Pass")
+else
+ io.write("FAIL")
+end
+print("")
diff --git a/challenge-149/roger-bell-west/lua/ch-2.lua b/challenge-149/roger-bell-west/lua/ch-2.lua
new file mode 100755
index 0000000000..b640896c01
--- /dev/null
+++ b/challenge-149/roger-bell-west/lua/ch-2.lua
@@ -0,0 +1,61 @@
+#! /usr/bin/lua
+
+function ls(base)
+ max=0
+ for i = base-1, 0, -1 do
+ max = max * base + i
+ end
+ t=math.floor(math.sqrt(max))
+ digits="0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"
+ while true do
+ s=t*t
+ v=true
+ c={}
+ for i = 0,base-1 do
+ table.insert(c,0)
+ end
+ dg=""
+ while s > 0 do
+ d = s % base + 1
+ c[d] = c[d] + 1
+ if c[d] > 1 then
+ v=false
+ break
+ end
+ s=math.floor(s/base)
+ dg = string.sub(digits,d,d) .. dg
+ end
+ if v then
+ return dg
+ end
+ t = t - 1
+ end
+end
+
+if ls(2) == "1" then
+ io.write("Pass")
+else
+ io.write("FAIL")
+end
+io.write(" ")
+
+if ls(4) == "3201" then
+ io.write("Pass")
+else
+ io.write("FAIL")
+end
+io.write(" ")
+
+if ls(10) == "9814072356" then
+ io.write("Pass")
+else
+ io.write("FAIL")
+end
+io.write(" ")
+
+if ls(12) == "B8750A649321" then
+ io.write("Pass")
+else
+ io.write("FAIL")
+end
+print("")
diff --git a/challenge-149/roger-bell-west/perl/ch-1.pl b/challenge-149/roger-bell-west/perl/ch-1.pl
new file mode 100755
index 0000000000..c603706822
--- /dev/null
+++ b/challenge-149/roger-bell-west/perl/ch-1.pl
@@ -0,0 +1,35 @@
+#! /usr/bin/perl
+
+use strict;
+use warnings;
+
+use Test::More tests => 3;
+
+is_deeply(fds(8),[0, 1, 2, 3, 5, 8, 10, 11],'example 1');
+is_deeply(fds(20),[0, 1, 2, 3, 5, 8, 10, 11, 12, 14, 17, 20, 21, 23, 26, 30, 32, 35, 41, 44],'example 2');
+is_deeply(fds(61),[0, 1, 2, 3, 5, 8, 10, 11, 12, 14, 17, 20, 21, 23, 26, 30, 32, 35, 41, 44, 49, 50, 53, 58, 62, 67, 71, 76, 80, 85, 94, 100, 101, 102, 104, 107, 110, 111, 113, 116, 120, 122, 125, 131, 134, 139, 140, 143, 148, 152, 157, 161, 166, 170, 175, 184, 193, 200, 201, 203, 206],'example 3');
+
+sub fds {
+ my $n=shift;
+ my @o;
+ my @f=(1,0);
+ my %ft=map {$_ => 1} @f;
+ my $k=0;
+ while (scalar @o < $n) {
+ my $ds=0;
+ my $j=$k;
+ while ($j > 0) {
+ $ds += ($j % 10);
+ $j=int($j/10);
+ }
+ while ($f[0] < $ds) {
+ @f=($f[1]+$f[0],$f[0]);
+ $ft{$f[0]}=1;
+ }
+ if (exists $ft{$ds}) {
+ push @o,$k;
+ }
+ $k++;
+ }
+ return \@o;
+}
diff --git a/challenge-149/roger-bell-west/perl/ch-2.pl b/challenge-149/roger-bell-west/perl/ch-2.pl
new file mode 100755
index 0000000000..2145d32724
--- /dev/null
+++ b/challenge-149/roger-bell-west/perl/ch-2.pl
@@ -0,0 +1,42 @@
+#! /usr/bin/perl
+
+use strict;
+use warnings;
+
+use Test::More tests => 4;
+
+is(ls(2),'1','example 1');
+is(ls(4),'3201','example 2');
+is(ls(10),'9814072356','example 3');
+is(ls(12),'B8750A649321','example 4');
+
+sub ls {
+ my $base=shift;
+ my $max=0;
+ for (my $i=$base-1;$i >= 0; $i--) {
+ $max *= $base;
+ $max += $i;
+ }
+ my $t=int(sqrt($max));
+ my @digits=('0'..'9','A'..'Z');
+ while (1) {
+ my $s=$t*$t;
+ my $v=1;
+ my @c=(0) x $base;
+ my @dg;
+ while ($s > 0) {
+ my $d=$s % $base;
+ $c[$d]++;
+ if ($c[$d] > 1) {
+ $v=0;
+ last;
+ }
+ $s = int($s/$base);
+ unshift @dg,$digits[$d];
+ }
+ if ($v) {
+ return join('',@dg);
+ }
+ $t--;
+ }
+}
diff --git a/challenge-149/roger-bell-west/postscript/ch-1.ps b/challenge-149/roger-bell-west/postscript/ch-1.ps
new file mode 100644
index 0000000000..d2aba414ba
--- /dev/null
+++ b/challenge-149/roger-bell-west/postscript/ch-1.ps
@@ -0,0 +1,80 @@
+%!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
+
+/i2s {
+ dup 0 le {
+ (0)
+ } {
+ dup log cvi 1 add string cvs
+ } ifelse
+} bind def
+
+/fds {
+ /n exch def
+ /ft n 4 mul dict def
+ /out 0 array def
+ /f [ 0 1 ] def
+ f {
+ ft exch true put
+ } forall
+ /k 0 def
+ {
+ /ds 0 def
+ /j k def
+ {
+ j 0 gt {
+ /ds ds j 10 mod add def
+ /j j 10 idiv def
+ } {
+ exit
+ } ifelse
+ } loop
+ {
+ f 0 get ds gt {
+ exit
+ } if
+ f 0 get f 1 get add
+ f 1 get f exch 0 exch put
+ f exch 1 exch put
+ ft f 0 get true put
+ } loop
+ ft ds known {
+ /out out k apush def
+ out length n ge {
+ exit
+ } if
+ } if
+ /k k 1 add def
+ } loop
+ out
+} bind def
+
+8 fds [0 1 2 3 5 8 10 11 ] aeq { (Pass) } { (FAIL) } ifelse print ( ) print
+
+20 fds [ 0 1 2 3 5 8 10 11 12 14 17 20 21 23 26 30 32 35 41 44] aeq { (Pass) } { (FAIL) } ifelse print ( ) print
+
+61 fds [0 1 2 3 5 8 10 11 12 14 17 20 21 23 26 30 32 35 41 44 49 50 53 58 62 67 71 76 80 85 94 100 101 102 104 107 110 111 113 116 120 122 125 131 134 139 140 143 148 152 157 161 166 170 175 184 193 200 201 203 206 ] aeq { (Pass) } { (FAIL) } ifelse =
diff --git a/challenge-149/roger-bell-west/postscript/ch-2.ps b/challenge-149/roger-bell-west/postscript/ch-2.ps
new file mode 100644
index 0000000000..45d80749c5
--- /dev/null
+++ b/challenge-149/roger-bell-west/postscript/ch-2.ps
@@ -0,0 +1,63 @@
+%!PS
+
+/ls {
+ /base exch def
+ /max 0 def
+ base 1 sub -1 0 {
+ /max max base mul def
+ max add /max exch def
+ } for
+ /t max sqrt cvi def
+ /digits (0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ) def
+ {
+ /s t t mul def
+ /v true def
+ /c base array def
+ 0 1 base 1 sub {
+ c exch 0 put
+ } for
+ /dg base string def
+ /i base def
+ {
+ s 0 le {
+ exit
+ } if
+ /d s base mod def
+ c d get 1 add c exch d exch put
+ c d get 1 gt {
+ /v false def
+ exit
+ } if
+ /s s base idiv def
+ /i i 1 sub def
+ dg i digits d get put
+ } loop
+ v {
+ exit
+ } if
+ /t t 1 sub def
+ } loop
+ /st 0 def
+ /i 1 def
+ dg {
+ 0 eq {
+ /st i def
+ } if
+ /i i 1 add def
+ } forall
+ st 0 gt {
+ dg st base st sub getinterval
+ } {
+ dg
+ } ifelse
+} bind def
+
+2 ls (1) eq { (Pass) } { (FAIL) } ifelse
+print ( ) print
+4 ls (3201) eq { (Pass) } { (FAIL) } ifelse
+print ( ) print
+10 ls (9814072356) eq { (Pass) } { (FAIL) } ifelse
+print ( ) print
+12 ls (B8750A649321) eq { (Pass) } { (FAIL) } ifelse
+=
+
diff --git a/challenge-149/roger-bell-west/python/ch-1.py b/challenge-149/roger-bell-west/python/ch-1.py
new file mode 100755
index 0000000000..984166c999
--- /dev/null
+++ b/challenge-149/roger-bell-west/python/ch-1.py
@@ -0,0 +1,39 @@
+#! /usr/bin/python3
+
+import unittest
+
+from math import floor
+
+def fds(n):
+ o=[]
+ f=[1,0]
+ ft=set(f)
+ k=0
+ while len(o) < n:
+ ds=0
+ j=k
+ while (j > 0):
+ ds += j % 10
+ j //= 10
+ while f[0] < ds:
+ t=f[1]+f[0]
+ f[1]=f[0]
+ f[0]=t
+ ft.add(f[0])
+ if ds in ft:
+ o.append(k)
+ k += 1
+ return o
+
+class TestFds(unittest.TestCase):
+
+ def test_ex1(self):
+ self.assertEqual(fds(8),[0, 1, 2, 3, 5, 8, 10, 11],'example 1')
+
+ def test_ex2(self):
+ self.assertEqual(fds(20),[0, 1, 2, 3, 5, 8, 10, 11, 12, 14, 17, 20, 21, 23, 26, 30, 32, 35, 41, 44],'example 2')
+
+ def test_ex3(self):
+ self.assertEqual(fds(61),[0, 1, 2, 3, 5, 8, 10, 11, 12, 14, 17, 20, 21, 23, 26, 30, 32, 35, 41, 44, 49, 50, 53, 58, 62, 67, 71, 76, 80, 85, 94, 100, 101, 102, 104, 107, 110, 111, 113, 116, 120, 122, 125, 131, 134, 139, 140, 143, 148, 152, 157, 161, 166, 170, 175, 184, 193, 200, 201, 203, 206],'example 3')
+
+unittest.main()
diff --git a/challenge-149/roger-bell-west/python/ch-2.py b/challenge-149/roger-bell-west/python/ch-2.py
new file mode 100755
index 0000000000..4306dd9c8e
--- /dev/null
+++ b/challenge-149/roger-bell-west/python/ch-2.py
@@ -0,0 +1,45 @@
+#! /usr/bin/python3
+
+import unittest
+
+from math import sqrt,floor
+
+def ls(base):
+ max=0
+ for i in reversed(range(base+1)):
+ max *= base
+ max += i
+ digits="0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"
+ t=floor(sqrt(max))
+ while True:
+ s=t*t
+ v=True
+ c=[0 for i in range(base)]
+ dg=""
+ while s > 0:
+ d=s % base
+ c[d] += 1
+ if c[d] > 1:
+ v=False
+ break
+ s //= base
+ dg=digits[d] + dg
+ if v:
+ return dg
+ t -= 1
+
+class TestLs(unittest.TestCase):
+
+ def test_ex1(self):
+ self.assertEqual(ls(2),"1",'example 1')
+
+ def test_ex2(self):
+ self.assertEqual(ls(4),"3201",'example 2')
+
+ def test_ex3(self):
+ self.assertEqual(ls(10),"9814072356",'example 3')
+
+ def test_ex4(self):
+ self.assertEqual(ls(12),"B8750A649321",'example 4')
+
+unittest.main()
diff --git a/challenge-149/roger-bell-west/raku/ch-1.p6 b/challenge-149/roger-bell-west/raku/ch-1.p6
new file mode 100755
index 0000000000..7edd2b4dd3
--- /dev/null
+++ b/challenge-149/roger-bell-west/raku/ch-1.p6
@@ -0,0 +1,33 @@
+#! /usr/bin/perl6
+
+use Test;
+
+plan 3;
+
+is-deeply(fds(8),[0, 1, 2, 3, 5, 8, 10, 11],'example 1');
+is-deeply(fds(20),[0, 1, 2, 3, 5, 8, 10, 11, 12, 14, 17, 20, 21, 23, 26, 30, 32, 35, 41, 44],'example 2');
+is-deeply(fds(61),[0, 1, 2, 3, 5, 8, 10, 11, 12, 14, 17, 20, 21, 23, 26, 30, 32, 35, 41, 44, 49, 50, 53, 58, 62, 67, 71, 76, 80, 85, 94, 100, 101, 102, 104, 107, 110, 111, 113, 116, 120, 122, 125, 131, 134, 139, 140, 143, 148, 152, 157, 161, 166, 170, 175, 184, 193, 200, 201, 203, 206],'example 3');
+
+sub fds($n) {
+ my @o;
+ my @f=[1,0];
+ my $ft=SetHash.new(@f);
+ my $k=0;
+ while (@o.elems < $n) {
+ my $ds=0;
+ my $j=$k;
+ while ($j > 0) {
+ $ds += ($j % 10);
+ $j div= 10;
+ }
+ while (@f[0] < $ds) {
+ @f=[@f[1]+@f[0],@f[0]];
+ $ft{@f[0]}++;
+ }
+ if ($ft{$ds}:exists) {
+ push @o,$k;
+ }
+ $k++;
+ }
+ return @o;
+}
diff --git a/challenge-149/roger-bell-west/raku/ch-2.p6 b/challenge-149/roger-bell-west/raku/ch-2.p6
new file mode 100755
index 0000000000..4243aa7a44
--- /dev/null
+++ b/challenge-149/roger-bell-west/raku/ch-2.p6
@@ -0,0 +1,41 @@
+#! /usr/bin/perl6
+
+use Test;
+
+plan 4;
+
+is(ls(2),'1','example 1');
+is(ls(4),'3201','example 2');
+is(ls(10),'9814072356','example 3');
+is(ls(12),'B8750A649321','example 4');
+
+sub ls($base) {
+ my $max=0;
+ loop (my $i=$base-1;$i >= 0; $i--) {
+ $max *= $base;
+ $max += $i;
+ }
+ my $t=floor(sqrt($max));
+ my @digits=['0'..'9'];
+ @digits.append('A'..'Z');
+ while (1) {
+ my $s=$t*$t;
+ my $v=True;
+ my @c=0 xx $base;
+ my @dg;
+ while ($s > 0) {
+ my $d=$s % $base;
+ @c[$d]++;
+ if (@c[$d] > 1) {
+ $v=False;
+ last;
+ }
+ $s = floor($s/$base);
+ unshift @dg,@digits[$d];
+ }
+ if ($v) {
+ return join('',@dg);
+ }
+ $t--;
+ }
+}
diff --git a/challenge-149/roger-bell-west/ruby/ch-1.rb b/challenge-149/roger-bell-west/ruby/ch-1.rb
new file mode 100755
index 0000000000..ff1f80c702
--- /dev/null
+++ b/challenge-149/roger-bell-west/ruby/ch-1.rb
@@ -0,0 +1,47 @@
+#! /usr/bin/ruby
+
+require 'test/unit'
+
+require 'set'
+
+def fds(n)
+ o=[]
+ f=[1,0]
+ ft=Set.new(f)
+ k=0
+ while o.length < n do
+ ds=0
+ j=k
+ while j > 0 do
+ ds += j % 10
+ j = (j/10).to_i
+ end
+ while f[0] < ds do
+ t=f[1]+f[0]
+ f[1]=f[0]
+ f[0]=t
+ ft.add(f[0])
+ end
+ if ft.include?(ds) then
+ o.push(k)
+ end
+ k += 1
+ end
+ return o
+end
+
+class TestFds < Test::Unit::TestCase
+
+ def test_ex1
+ assert_equal([0, 1, 2, 3, 5, 8, 10, 11],fds(8))
+ end
+
+ def test_ex2
+ assert_equal([0, 1, 2, 3, 5, 8, 10, 11, 12, 14, 17, 20, 21, 23, 26, 30, 32, 35, 41, 44],fds(20))
+ end
+
+ def test_ex3
+ assert_equal([0, 1, 2, 3, 5, 8, 10, 11, 12, 14, 17, 20, 21, 23, 26, 30, 32, 35, 41, 44, 49, 50, 53, 58, 62, 67, 71, 76, 80, 85, 94, 100, 101, 102, 104, 107, 110, 111, 113, 116, 120, 122, 125, 131, 134, 139, 140, 143, 148, 152, 157, 161, 166, 170, 175, 184, 193, 200, 201, 203, 206],fds(61))
+ end
+
+end
diff --git a/challenge-149/roger-bell-west/ruby/ch-2.rb b/challenge-149/roger-bell-west/ruby/ch-2.rb
new file mode 100755
index 0000000000..d50cfb33d4
--- /dev/null
+++ b/challenge-149/roger-bell-west/ruby/ch-2.rb
@@ -0,0 +1,53 @@
+#! /usr/bin/ruby
+
+require 'test/unit'
+
+def ls(base)
+ max=0
+ base.downto(0) do |i|
+ max *= base
+ max += i
+ end
+ digits="0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"
+ t=Integer.sqrt(max)
+ while true do
+ s=t*t
+ v=true
+ c=Array.new(base) { 0 }
+ dg=""
+ while s > 0 do
+ d = s % base
+ c[d] += 1
+ if c[d] > 1 then
+ v=false
+ break
+ end
+ s = (s/base).to_i
+ dg = digits[d] + dg
+ end
+ if v then
+ return dg
+ end
+ t -= 1
+ end
+end
+
+class TestLs < Test::Unit::TestCase
+
+ def test_ex1
+ assert_equal("1",ls(2))
+ end
+
+ def test_ex2
+ assert_equal("3201",ls(4))
+ end
+
+ def test_ex3
+ assert_equal("9814072356",ls(10))
+ end
+
+ def test_ex4
+ assert_equal("B8750A649321",ls(12))
+ end
+
+end
diff --git a/challenge-149/roger-bell-west/rust/ch-1.rs b/challenge-149/roger-bell-west/rust/ch-1.rs
new file mode 100755
index 0000000000..d026679394
--- /dev/null
+++ b/challenge-149/roger-bell-west/rust/ch-1.rs
@@ -0,0 +1,45 @@
+#! /bin/sh
+//usr/bin/env rustc --test $0 -o ${0}x && ./${0}x; rm -f ${0}x ; exit
+
+use std::collections::HashSet;
+
+#[test]
+fn test_ex1() {
+ assert_eq!(fds(8),vec![0, 1, 2, 3, 5, 8, 10, 11]);
+}
+
+#[test]
+fn test_ex2() {
+ assert_eq!(fds(20),vec![0, 1, 2, 3, 5, 8, 10, 11, 12, 14, 17, 20, 21, 23, 26, 30, 32, 35, 41, 44]);
+}
+
+#[test]
+fn test_ex3() {
+ assert_eq!(fds(61),vec![0, 1, 2, 3, 5, 8, 10, 11, 12, 14, 17, 20, 21, 23, 26, 30, 32, 35, 41, 44, 49, 50, 53, 58, 62, 67, 71, 76, 80, 85, 94, 100, 101, 102, 104, 107, 110, 111, 113, 116, 120, 122, 125, 131, 134, 139, 140, 143, 148, 152, 157, 161, 166, 170, 175, 184, 193, 200, 201, 203, 206]);
+}
+
+fn fds(n: u32) -> Vec<u32> {
+ let mut o=Vec::new();
+ let mut f=[1,0];
+ let mut ft: HashSet<u32>=HashSet::from(f);
+ let mut k=0;
+ while o.len() < n as usize {
+ let mut ds=0;
+ let mut j=k;
+ while j > 0 {
+ ds += j % 10;
+ j /= 10;
+ }
+ while f[0] < ds {
+ let t=f[1]+f[0];
+ f[1]=f[0];
+ f[0]=t;
+ ft.insert(f[0]);
+ }
+ if ft.contains(&ds) {
+ o.push(k);
+ }
+ k += 1;
+ }
+ o
+}
diff --git a/challenge-149/roger-bell-west/rust/ch-2.rs b/challenge-149/roger-bell-west/rust/ch-2.rs
new file mode 100755
index 0000000000..61d970c1ab
--- /dev/null
+++ b/challenge-149/roger-bell-west/rust/ch-2.rs
@@ -0,0 +1,54 @@
+#! /bin/sh
+//usr/bin/env rustc --test $0 -o ${0}x && ./${0}x; rm -f ${0}x ; exit
+
+use std::convert::TryInto;
+
+#[test]
+fn test_ex1() {
+ assert_eq!(ls(2),"1");
+}
+
+#[test]
+fn test_ex2() {
+ assert_eq!(ls(4),"3201");
+}
+
+#[test]
+fn test_ex3() {
+ assert_eq!(ls(10),"9814072356");
+}
+
+#[test]
+fn test_ex4() {
+ assert_eq!(ls(12),"B8750A649321");
+}
+
+fn ls(base: u64) -> String {
+ let mut max=0u64;
+ for i in (0..base).rev() {
+ max *= base;
+ max += i;
+ }
+ let mut t=(max as f64).sqrt() as u64;
+ loop {
+ let mut s=t*t;
+ let mut v=true;
+ let mut c=vec![0u64;base.try_into().unwrap()];
+ let mut dg: Vec<char>=Vec::new();
+ while s > 0 {
+ let d = (s % base) as usize;