aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMohammad Sajid Anwar <Mohammad.Anwar@yahoo.com>2024-03-12 11:33:32 +0000
committerGitHub <noreply@github.com>2024-03-12 11:33:32 +0000
commitcc76368fff2cead23a96361849a30447c3a02b87 (patch)
treecbabbe8f8a0b47f99981bbaa9bde78e4cb02c0f0
parent14ae65cd517d955713cab891458fd67172e57881 (diff)
parentce6d2a4181a05281b6a9f56de4830505a1505c4d (diff)
downloadperlweeklychallenge-club-cc76368fff2cead23a96361849a30447c3a02b87.tar.gz
perlweeklychallenge-club-cc76368fff2cead23a96361849a30447c3a02b87.tar.bz2
perlweeklychallenge-club-cc76368fff2cead23a96361849a30447c3a02b87.zip
Merge pull request #9736 from Firedrake/rogerbw-challenge-260
RogerBW solutions for challenge no. 260
-rwxr-xr-xchallenge-260/roger-bell-west/javascript/ch-1.js38
-rwxr-xr-xchallenge-260/roger-bell-west/javascript/ch-2.js68
-rw-r--r--challenge-260/roger-bell-west/kotlin/ch-1.kt34
-rw-r--r--challenge-260/roger-bell-west/kotlin/ch-2.kt77
-rwxr-xr-xchallenge-260/roger-bell-west/lua/ch-1.lua42
-rwxr-xr-xchallenge-260/roger-bell-west/lua/ch-2.lua102
-rwxr-xr-xchallenge-260/roger-bell-west/perl/ch-1.pl22
-rwxr-xr-xchallenge-260/roger-bell-west/perl/ch-2.pl29
-rw-r--r--challenge-260/roger-bell-west/postscript/ch-1.ps91
-rw-r--r--challenge-260/roger-bell-west/postscript/ch-2.ps290
-rwxr-xr-xchallenge-260/roger-bell-west/python/ch-1.py27
-rwxr-xr-xchallenge-260/roger-bell-west/python/ch-2.py29
-rwxr-xr-xchallenge-260/roger-bell-west/raku/ch-1.p619
-rwxr-xr-xchallenge-260/roger-bell-west/raku/ch-2.p624
-rwxr-xr-xchallenge-260/roger-bell-west/ruby/ch-1.rb33
-rwxr-xr-xchallenge-260/roger-bell-west/ruby/ch-2.rb36
-rwxr-xr-xchallenge-260/roger-bell-west/rust/ch-1.rs26
-rwxr-xr-xchallenge-260/roger-bell-west/rust/ch-2.rs33
-rw-r--r--challenge-260/roger-bell-west/scala/ch-1.scala36
-rw-r--r--challenge-260/roger-bell-west/scala/ch-2.scala76
-rw-r--r--challenge-260/roger-bell-west/tests.yaml36
21 files changed, 1168 insertions, 0 deletions
diff --git a/challenge-260/roger-bell-west/javascript/ch-1.js b/challenge-260/roger-bell-west/javascript/ch-1.js
new file mode 100755
index 0000000000..f662f3c60d
--- /dev/null
+++ b/challenge-260/roger-bell-west/javascript/ch-1.js
@@ -0,0 +1,38 @@
+#! /usr/bin/node
+
+"use strict"
+
+function uniqueoccurrences(a) {
+ let c = new Map;
+ for (let n of a) {
+ if (c.has(n)) {
+ c.set(n, c.get(n) + 1);
+ } else {
+ c.set(n, 1);
+ }
+ }
+ if (c.size == new Set(c.values()).size) {
+ return 1;
+ } else {
+ return 0;
+ }
+}
+
+if (uniqueoccurrences([1, 2, 2, 1, 1, 3]) == 1) {
+ process.stdout.write("Pass");
+} else {
+ process.stdout.write("FAIL");
+}
+process.stdout.write(" ");
+if (uniqueoccurrences([1, 2, 3]) == 0) {
+ process.stdout.write("Pass");
+} else {
+ process.stdout.write("FAIL");
+}
+process.stdout.write(" ");
+if (uniqueoccurrences([-2, 0, 1, -2, 1, 1, 0, 1, -2, 9]) == 1) {
+ process.stdout.write("Pass");
+} else {
+ process.stdout.write("FAIL");
+}
+process.stdout.write("\n");
diff --git a/challenge-260/roger-bell-west/javascript/ch-2.js b/challenge-260/roger-bell-west/javascript/ch-2.js
new file mode 100755
index 0000000000..0c7fc40efd
--- /dev/null
+++ b/challenge-260/roger-bell-west/javascript/ch-2.js
@@ -0,0 +1,68 @@
+#! /usr/bin/node
+
+"use strict"
+
+function permute(a) {
+ let out = [];
+ let n=a.length;
+ let c=[];
+ for (let i = 0; i < n; i++) {
+ c.push(0);
+ }
+ out.push([...a]);
+ let i=0;
+ while (true) {
+ if (i >= n) {
+ break;
+ }
+ if (c[i] < i) {
+ if (i % 2 == 0) {
+ [a[0],a[i]] = [a[i],a[0]];
+ } else {
+ [a[c[i]],a[i]] = [a[i],a[c[i]]];
+ }
+ out.push([...a]);
+ c[i]++;
+ i=0;
+ } else {
+ c[i]=0;
+ i++;
+ }
+ }
+ return out;
+}
+
+function dictionaryrank(a) {
+ const c = a.split("");
+ let d = new Set;
+ for (let o of permute(c)) {
+ d.add(o.join(""));
+ }
+ let dd = new Array(...d);
+ dd.sort();
+ for (let i = 0; i < dd.length; i++) {
+ if (dd[i] == a) {
+ return i + 1;
+ }
+ }
+ return 0;
+}
+
+if (dictionaryrank('CAT') == 3) {
+ process.stdout.write("Pass");
+} else {
+ process.stdout.write("FAIL");
+}
+process.stdout.write(" ");
+if (dictionaryrank('GOOGLE') == 88) {
+ process.stdout.write("Pass");
+} else {
+ process.stdout.write("FAIL");
+}
+process.stdout.write(" ");
+if (dictionaryrank('SECRET') == 255) {
+ process.stdout.write("Pass");
+} else {
+ process.stdout.write("FAIL");
+}
+process.stdout.write("\n");
diff --git a/challenge-260/roger-bell-west/kotlin/ch-1.kt b/challenge-260/roger-bell-west/kotlin/ch-1.kt
new file mode 100644
index 0000000000..844714ccce
--- /dev/null
+++ b/challenge-260/roger-bell-west/kotlin/ch-1.kt
@@ -0,0 +1,34 @@
+fun uniqueoccurrences(a: List<Int>): Int {
+ var c = mutableMapOf<Int, Int>().withDefault({0})
+ for (n in a) {
+ c.set(n, c.getValue(n) + 1)
+ }
+ if (c.size == c.values.toSet().size) {
+ return 1
+ } else {
+ return 0
+ }
+}
+
+fun main() {
+
+ if (uniqueoccurrences(listOf(1, 2, 2, 1, 1, 3)) == 1) {
+ print("Pass")
+ } else {
+ print("Fail")
+ }
+ print(" ")
+ if (uniqueoccurrences(listOf(1, 2, 3)) == 0) {
+ print("Pass")
+ } else {
+ print("Fail")
+ }
+ print(" ")
+ if (uniqueoccurrences(listOf(-2, 0, 1, -2, 1, 1, 0, 1, -2, 9)) == 1) {
+ print("Pass")
+ } else {
+ print("Fail")
+ }
+ println("")
+
+}
diff --git a/challenge-260/roger-bell-west/kotlin/ch-2.kt b/challenge-260/roger-bell-west/kotlin/ch-2.kt
new file mode 100644
index 0000000000..c437a9e4fd
--- /dev/null
+++ b/challenge-260/roger-bell-west/kotlin/ch-2.kt
@@ -0,0 +1,77 @@
+fun permute(aa: List<Char>): ArrayList<List<Char>> {
+ var a = ArrayList<Char>()
+ for (i in aa) {
+ a.add(i)
+ }
+ var out = ArrayList<List<Char>>()
+ val n = a.size
+ var c = ArrayList<Int>();
+ for (i in 0..n-1) {
+ c.add(0)
+ }
+ out.add(a.toList())
+ var i = 0
+ while (true) {
+ if (i >= n) {
+ break
+ }
+ if (c[i] < i) {
+ if (i % 2 == 0) {
+ val tmp = a[0]
+ a[0] = a[i]
+ a[i] = tmp
+ } else {
+ val tmp = a[c[i]]
+ a[c[i]] = a[i]
+ a[i] = tmp
+ }
+ out.add(a.toList())
+ c[i] += 1
+ i = 0
+ } else {
+ c[i] = 0
+ i += 1
+ }
+ }
+ return out
+}
+
+fun dictionaryrank(a: String): Int {
+ val c = a.toCharArray().toList()
+ var d = mutableSetOf<String>()
+ for (o in permute(c)) {
+ d.add(o.joinToString(""))
+ }
+ var dd = ArrayList(d)
+ dd.sort()
+ var r = 0
+ dd.forEachIndexed{i, s ->
+ if (s == a) {
+ r = i + 1
+ }
+ }
+ return r
+}
+
+fun main() {
+
+ if (dictionaryrank("CAT") == 3) {
+ print("Pass")
+ } else {
+ print("Fail")
+ }
+ print(" ")
+ if (dictionaryrank("GOOGLE") == 88) {
+ print("Pass")
+ } else {
+ print("Fail")
+ }
+ print(" ")
+ if (dictionaryrank("SECRET") == 255) {
+ print("Pass")
+ } else {
+ print("Fail")
+ }
+ println("")
+
+}
diff --git a/challenge-260/roger-bell-west/lua/ch-1.lua b/challenge-260/roger-bell-west/lua/ch-1.lua
new file mode 100755
index 0000000000..2cdfb441b3
--- /dev/null
+++ b/challenge-260/roger-bell-west/lua/ch-1.lua
@@ -0,0 +1,42 @@
+#! /usr/bin/lua
+
+function uniqueoccurrences(a)
+ local c = {}
+ for _, n in ipairs(a) do
+ if c[n] == nil then
+ c[n] = 1
+ else
+ c[n] = c[n] + 1
+ end
+ end
+ local s = {}
+ for _, v in pairs(c) do
+ if s[v] ~= nil then
+ return 0
+ end
+ s[v] = true
+ end
+ return 1
+end
+
+if uniqueoccurrences({1, 2, 2, 1, 1, 3}) == 1 then
+ io.write("Pass")
+else
+ io.write("FAIL")
+end
+io.write(" ")
+
+if uniqueoccurrences({1, 2, 3}) == 0 then
+ io.write("Pass")
+else
+ io.write("FAIL")
+end
+io.write(" ")
+
+if uniqueoccurrences({-2, 0, 1, -2, 1, 1, 0, 1, -2, 9}) == 1 then
+ io.write("Pass")
+else
+ io.write("FAIL")
+end
+print("")
+
diff --git a/challenge-260/roger-bell-west/lua/ch-2.lua b/challenge-260/roger-bell-west/lua/ch-2.lua
new file mode 100755
index 0000000000..d9407cf3ad
--- /dev/null
+++ b/challenge-260/roger-bell-west/lua/ch-2.lua
@@ -0,0 +1,102 @@
+#! /usr/bin/lua
+
+function deepcopy(src)
+ local dst = {}
+ for k, v in pairs(src) do
+ if type(v) == "table" then
+ v = deepcopy(v)
+ end
+ dst[k] = v
+ end
+ return dst
+end
+
+function permute(a)
+ local out = {}
+ local n = #a
+ local c = {}
+ for i = 1,n do
+ table.insert(c, 1)
+ end
+ table.insert(out, deepcopy(a))
+ local i=1
+ while true do
+ if i > n then
+ break
+ end
+ if c[i] < i then
+ if i % 2 == 1 then
+ a[1],a[i] = a[i],a[1]
+ else
+ a[c[i]],a[i] = a[i],a[c[i]]
+ end
+ table.insert(out, deepcopy(a))
+ c[i] = c[i]+1
+ i = 1
+ else
+ c[i] = 1
+ i = i+1
+ end
+ end
+ return out
+end
+
+function split(t)
+ local cl = {}
+ string.gsub(t,
+ "(.)",
+ function(c)
+ table.insert(cl, c)
+ end
+ )
+ return cl
+end
+
+function join(t)
+ local out=""
+ for k,v in pairs(t) do
+ out = out .. v
+ end
+ return out
+end
+
+function dictionaryrank(a)
+ local c = split(a)
+ local d = {}
+ for _, o in ipairs(permute(c)) do
+ d[join(o)] = true
+ end
+ local dd = {}
+ for k, _ in pairs(d) do
+ table.insert(dd, k)
+ end
+ table.sort(dd)
+ for i, s in ipairs(dd) do
+ if s == a then
+ return i
+ end
+ end
+ return 0
+end
+
+if dictionaryrank("CAT") == 3 then
+ io.write("Pass")
+else
+ io.write("FAIL")
+end
+io.write(" ")
+
+if dictionaryrank("GOOGLE") == 88 then
+ io.write("Pass")
+else
+ io.write("FAIL")
+end
+io.write(" ")
+
+if dictionaryrank("SECRET") == 255 then
+ io.write("Pass")
+else
+ io.write("FAIL")
+end
+print("")
+
diff --git a/challenge-260/roger-bell-west/perl/ch-1.pl b/challenge-260/roger-bell-west/perl/ch-1.pl
new file mode 100755
index 0000000000..b644823003
--- /dev/null
+++ b/challenge-260/roger-bell-west/perl/ch-1.pl
@@ -0,0 +1,22 @@
+#! /usr/bin/perl
+
+use strict;
+use warnings;
+use experimental 'signatures';
+
+use Test::More tests => 3;
+
+is(uniqueoccurrences([1, 2, 2, 1, 1, 3]), 1, 'example 1');
+is(uniqueoccurrences([1, 2, 3]), 0, 'example 2');
+is(uniqueoccurrences([-2, 0, 1, -2, 1, 1, 0, 1, -2, 9]), 1, 'example 3');
+
+sub uniqueoccurrences($a) {
+ my %c;
+ map {$c{$_}++} @{$a};
+ my %d = map {$_ => 1} values %c;
+ if (scalar keys %d == scalar keys %c) {
+ return 1;
+ } else {
+ return 0;
+ }
+}
diff --git a/challenge-260/roger-bell-west/perl/ch-2.pl b/challenge-260/roger-bell-west/perl/ch-2.pl
new file mode 100755
index 0000000000..ca2db96207
--- /dev/null
+++ b/challenge-260/roger-bell-west/perl/ch-2.pl
@@ -0,0 +1,29 @@
+#! /usr/bin/perl
+
+use strict;
+use warnings;
+use experimental 'signatures';
+
+use Test::More tests => 3;
+
+is(dictionaryrank('CAT'), 3, 'example 1');
+is(dictionaryrank('GOOGLE'), 88, 'example 2');
+is(dictionaryrank('SECRET'), 255, 'example 3');
+
+use Algorithm::Combinatorics qw(permutations);
+
+sub dictionaryrank($a) {
+ my @c = split '', $a;
+ my %d;
+ my $ip = permutations(\@c);
+ while (my $c = $ip->next) {
+ $d{join('', @{$c})} = 1;
+ }
+ my @dd = sort keys %d;
+ foreach my $i (0 .. $#dd) {
+ if ($dd[$i] eq $a) {
+ return $i + 1;
+ }
+ }
+ return 0;
+}
diff --git a/challenge-260/roger-bell-west/postscript/ch-1.ps b/challenge-260/roger-bell-west/postscript/ch-1.ps
new file mode 100644
index 0000000000..602ce57d34
--- /dev/null
+++ b/challenge-260/roger-bell-west/postscript/ch-1.ps
@@ -0,0 +1,91 @@
+%!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
+
+/values { % dict -> array of dict values
+ [ exch
+ {
+ exch pop
+ } forall
+ ]
+} bind def
+
+/toset { % array -> dict of (value, true)
+ << exch
+ {
+ true
+ } forall
+ >>
+} bind def
+
+/dget {
+ 3 1 roll
+ 2 copy
+ known {
+ get exch pop
+ } {
+ pop pop
+ } 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
+
+
+% end included library code
+
+/uniqueoccurrences {
+ 0 dict begin
+ /c 0 dict def
+ {
+ dup c exch 0 dget 1 add c 3 1 roll put
+ } forall
+ c values toset keys length c keys length eq {
+ 1
+ } {
+ 0
+ } ifelse
+ end
+} bind def
+
+(uniqueoccurrences) test.start
+[1 2 2 1 1 3] uniqueoccurrences 1 eq test
+[1 2 3] uniqueoccurrences 0 eq test
+[-2 0 1 -2 1 1 0 1 -2 9] uniqueoccurrences 1 eq test
+test.end
diff --git a/challenge-260/roger-bell-west/postscript/ch-2.ps b/challenge-260/roger-bell-west/postscript/ch-2.ps
new file mode 100644
index 0000000000..d35a2a9777
--- /dev/null
+++ b/challenge-260/roger-bell-west/postscript/ch-2.ps
@@ -0,0 +1,290 @@
+%!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
+
+/keys { % dict -> array of dict keys
+ [ exch
+ {
+ pop
+ } forall
+ ]
+} 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
+
+/permute { % [array] {proc} permute runs proc on each permutation of array
+ 7 dict begin
+ /permute.subproc exch def
+ /permute.a exch def
+ /permute.n permute.a length def
+ /permute.c [ permute.n { 0 } repeat ] def
+ permute.a permute.subproc
+ /permute.i 0 def
+ {
+ permute.i permute.n ge {
+ exit
+ } if
+ permute.c permute.i get permute.i lt {
+ permute.i 2 mod 0 eq {
+ 0 permute.i permute.swap
+ } {
+ permute.c permute.i get permute.i permute.swap
+ } ifelse
+ permute.a permute.subproc
+ permute.c permute.i get 1 add permute.c exch permute.i exch put
+ /permute.i 0 def
+ } {
+ permute.c permute.i 0 put
+ /permute.i permute.i 1 add def
+ } ifelse
+ } loop
+ end
+} bind def
+
+/quicksort {
+ { quicksort.cmp } quicksort.with_comparator
+} bind def
+
+/quicksort.swap {
+ 2 dict begin
+ /bi exch def
+ /ai exch def
+ arr ai get
+ arr bi get
+ arr exch ai exch put
+ arr exch bi exch put
+ end
+} bind def
+
+/quicksort.cmp {
+ 2 copy
+ lt {
+ pop pop -1
+ } {
+ gt {
+ 1
+ } {
+ 0
+ } ifelse
+ } ifelse
+} bind def
+
+/permute.swap {
+ /permute.bi exch def
+ /permute.ai exch def
+ permute.a permute.ai get
+ permute.a permute.bi get
+ permute.a exch permute.ai exch put
+ permute.a exch permute.bi exch put
+} 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
+
+/enumerate.array {
+ 1 dict begin
+ /a exch def
+ [
+ 0 1 a length 1 sub {
+ [ exch dup a exch get ]
+ } for
+ ]
+ end
+} bind def
+
+/a2s {
+ 2 dict begin
+ /i exch def
+ i length dup string /o exch def
+ 1 sub 0 exch 1 exch {
+ dup i 3 -1 roll get o 3 1 roll put
+ } for
+ o
+ end
+} bind def
+
+/map { % array proc -> array
+ 2 dict begin
+ /p exch def
+ [ exch
+ {
+ p
+ } forall
+ ]
+ end
+} bind def
+
+/s2a {
+ [ exch { } forall ]
+} bind def
+
+/quicksort.partition {
+ 3 dict begin
+ /pivot arr hi lo add 2 idiv get def
+ /i lo 1 sub def
+ /j hi 1 add def
+ {
+ {
+ /i i 1 add def
+ arr i get pivot cmp 0 ge {
+ exit
+ } if
+ } loop
+ {
+ /j j 1 sub def
+ arr j get pivot cmp 0 le {
+ exit
+ } if
+ } loop
+ i j ge {
+ j
+ exit
+ } if
+ i j quicksort.swap
+ } loop
+ end
+} bind def
+
+/quicksort.main { % lo hi -> (null)
+ 3 dict begin
+ /hi exch def
+ /lo exch def
+ /xit false def
+ lo 0 lt {
+ /xit true def
+ } if
+ hi 0 lt {
+ /xit true def
+ } if
+ lo hi ge {
+ /xit true def
+ } if
+ xit not {
+ /p quicksort.partition def
+ lo p quicksort.main
+ p 1 add hi quicksort.main
+ } if
+ end
+} bind def
+
+/test.start {
+ print (:) print
+ /test.pass 0 def
+ /test.count 0 def
+} bind def
+
+/quicksort.with_comparator { % [ a c b ] { comparator } -> [ a b c ]
+ 2 dict begin
+ /cmp exch def
+ /arr exch def
+ arr length 0 gt {
+ 0 arr length 1 sub quicksort.main
+ } if
+ arr
+ end
+} bind def
+
+
+% end included library code
+
+/dictionaryrank {
+ 0 dict begin
+ /a exch def
+ /l a length def
+ /d 0 dict def
+ a s2a { a2s d exch true put } permute
+ d keys { l string cvs } map quicksort enumerate.array {
+ aload pop
+ a deepeq {
+ 1 add
+ exit
+ } {
+ pop
+ } ifelse
+ } forall
+ end
+} bind def
+
+(dictionaryrank) test.start
+(CAT) dictionaryrank 3 eq test
+(GOOGLE) dictionaryrank 88 eq test
+(SECRET) dictionaryrank 255 eq test
+test.end
diff --git a/challenge-260/roger-bell-west/python/ch-1.py b/challenge-260/roger-bell-west/python/ch-1.py
new file mode 100755
index 0000000000..581f24f050
--- /dev/null
+++ b/challenge-260/roger-bell-west/python/ch-1.py
@@ -0,0 +1,27 @@
+#! /usr/bin/python3
+
+from collections import defaultdict
+
+def uniqueoccurrences(a):
+ c = defaultdict(lambda: 0)
+ for v in a:
+ c[v] += 1
+ if len(c) == len(set(c.values())):
+ return 1
+ else:
+ return 0
+
+import unittest
+
+class TestUniqueoccurrences(unittest.TestCase):
+
+ def test_ex1(self):
+ self.assertEqual(uniqueoccurrences([1, 2, 2, 1, 1, 3]), 1, 'example 1')
+
+ def test_ex2(self):
+ self.assertEqual(uniqueoccurrences([1, 2, 3]), 0, 'example 2')
+
+ def test_ex3(self):
+ self.assertEqual(uniqueoccurrences([-2, 0, 1, -2, 1, 1, 0, 1, -2, 9]), 1, 'example 3')
+
+unittest.main()
diff --git a/challenge-260/roger-bell-west/python/ch-2.py b/challenge-260/roger-bell-west/python/ch-2.py
new file mode 100755
index 0000000000..81eb658cbd
--- /dev/null
+++ b/challenge-260/roger-bell-west/python/ch-2.py
@@ -0,0 +1,29 @@
+#! /usr/bin/python3
+
+from itertools import permutations
+
+def dictionaryrank(a):
+ d = set()
+ for o in permutations(a):
+ d.add("".join(o))
+ dd = list(d)
+ dd.sort()
+ for i, s in enumerate(dd):
+ if s == a:
+ return i + 1
+ return 0
+
+import unittest
+
+class TestDictionaryrank(unittest.TestCase):
+
+ def test_ex1(self):
+ self.assertEqual(dictionaryrank("CAT"), 3, 'example 1')
+
+ def test_ex2(self):
+ self.assertEqual(dictionaryrank("GOOGLE"), 88, 'example 2')
+
+ def test_ex3(self):
+ self.assertEqual(dictionaryrank("SECRET"), 255, 'example 3')
+
+unittest.main()
diff --git a/challenge-260/roger-bell-west/raku/ch-1.p6 b/challenge-260/roger-bell-west/raku/ch-1.p6
new file mode 100755
index 0000000000..42523b7149
--- /dev/null
+++ b/challenge-260/roger-bell-west/raku/ch-1.p6
@@ -0,0 +1,19 @@
+#! /usr/bin/raku
+
+use Test;
+
+plan 3;
+
+is(uniqueoccurrences([1, 2, 2, 1, 1, 3]), 1, 'example 1');
+is(uniqueoccurrences([1, 2, 3]), 0, 'example 2');
+is(uniqueoccurrences([-2, 0, 1, -2, 1, 1, 0, 1, -2, 9]), 1, 'example 3');
+
+sub uniqueoccurrences(@a) {
+ my %c;
+ @a.map({%c{$_}++});
+ if (Set(%c.values).elems == %c.elems) {
+ return 1;
+ } else {
+ return 0;
+ }
+}
diff --git a/challenge-260/roger-bell-west/raku/ch-2.p6 b/challenge-260/roger-bell-west/raku/ch-2.p6
new file mode 100755
index 0000000000..57cd6222cb
--- /dev/null
+++ b/challenge-260/roger-bell-west/raku/ch-2.p6
@@ -0,0 +1,24 @@
+#! /usr/bin/raku
+
+use Test;
+
+plan 3;
+
+is(dictionaryrank('CAT'), 3, 'example 1');
+is(dictionaryrank('GOOGLE'), 88, 'example 2');
+is(dictionaryrank('SECRET'), 255, 'example 3');
+
+sub dictionaryrank($a) {
+ my @c = $a.comb;
+ my %d = SetHash.new;
+ for @c.permutations -> @o {
+ %d{@o.join("")}++;
+ }
+ my @dd = %d.keys.sort;
+ for 0 .. @dd.end -> $i {
+ if (@dd[$i] eq $a) {
+ return $i + 1;
+ }
+ }
+ return 0;
+}
diff --git a/challenge-260/roger-bell-west/ruby/ch-1.rb b/challenge-260/roger-bell-west/ruby/ch-1.rb
new file mode 100755
index 0000000000..687e1544db
--- /dev/null
+++ b/challenge-260/roger-bell-west/ruby/ch-1.rb
@@ -0,0 +1,33 @@
+#! /usr/bin/ruby
+
+require 'set'
+
+def uniqueoccurrences(a)
+ c = Hash.new(0)
+ a.each do |n|
+ c[n] += 1
+ end
+ if c.length == Set.new(c.values).length then
+ return 1
+ else
+ return 0
+ end
+end
+
+require 'test/unit'
+
+class TestUniqueoccurrences < Test::Unit::TestCase
+
+ def test_ex1
+ assert_equal(1, uniqueoccurrences([1, 2, 2, 1, 1, 3]))
+ end
+
+ def test_ex2
+ assert_equal(0, uniqueoccurrences([1, 2, 3]))
+ end
+
+ def test_ex3
+ assert_equal(1, uniqueoccurrences([-2, 0, 1, -2, 1, 1, 0, 1, -2, 9]))
+ end
+
+end
diff --git a/challenge-260/roger-bell-west/ruby/ch-2.rb b/challenge-260/roger-bell-west/ruby/ch-2.rb
new file mode 100755
index 0000000000..e02efe0973
--- /dev/null
+++ b/challenge-260/roger-bell-west/ruby/ch-2.rb
@@ -0,0 +1,36 @@
+#! /usr/bin/ruby
+
+require 'set'
+
+def dictionaryrank(a)
+ c = a.split('')
+ d = Set.new
+ c.permutation do |o|
+ d.add(o.join(''))
+ end
+ dd = d.to_a.sort
+ dd.each_with_index do |s, i|
+ if s == a then
+ return i + 1
+ end
+ end
+ return 0
+end
+
+require 'test/unit'
+
+class TestDictionaryrank < Test::Unit::TestCase
+
+ def test_ex1
+ assert_equal(3, dictionaryrank('CAT'))
+ end
+
+ def test_ex2
+ assert_equal(88, dictionaryrank('GOOGLE'))
+ end
+
+ def test_ex3
+ assert_equal(255, dictionaryrank('SECRET'))
+ end
+
+end
diff --git a/challenge-260/roger-bell-west/rust/ch-1.rs b/challenge-260/roger-bell-west/rust/ch-1.rs
new file mode 100755
index 0000000000..bf662964ad
--- /dev/null
+++ b/challenge-260/roger-bell-west/rust/ch-1.rs
@@ -0,0 +1,26 @@
+use counter::Counter;
+use std::collections::HashSet;
+
+#[test]
+fn test_ex1() {
+ assert_eq!(uniqueoccurrences(vec![1, 2, 2, 1, 1, 3]), 1);
+}
+
+#[test]
+fn test_ex2() {
+ assert_eq!(uniqueoccurrences(vec![1, 2, 3]), 0);
+}
+
+#[test]
+fn test_ex3() {
+ assert_eq!(uniqueoccurrences(vec