aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRoger Bell_West <roger@firedrake.org>2024-07-01 11:41:33 +0100
committerRoger Bell_West <roger@firedrake.org>2024-07-01 11:41:33 +0100
commit5b655b087361dccc9d5b8f05e7d07abcf101662d (patch)
tree31c620fc6f1e8a0265cf430b13f495500e8df35e
parentf18cb7a95e46b9ded70a2d1d932d0bb7b1772a67 (diff)
downloadperlweeklychallenge-club-5b655b087361dccc9d5b8f05e7d07abcf101662d.tar.gz
perlweeklychallenge-club-5b655b087361dccc9d5b8f05e7d07abcf101662d.tar.bz2
perlweeklychallenge-club-5b655b087361dccc9d5b8f05e7d07abcf101662d.zip
RogerBW solutions for challenge no. 276
-rwxr-xr-xchallenge-276/roger-bell-west/crystal/ch-1.cr18
-rwxr-xr-xchallenge-276/roger-bell-west/crystal/ch-2.cr20
-rwxr-xr-xchallenge-276/roger-bell-west/javascript/ch-1.js59
-rwxr-xr-xchallenge-276/roger-bell-west/javascript/ch-2.js29
-rw-r--r--challenge-276/roger-bell-west/kotlin/ch-1.kt59
-rw-r--r--challenge-276/roger-bell-west/kotlin/ch-2.kt25
-rwxr-xr-xchallenge-276/roger-bell-west/lua/ch-1.lua60
-rwxr-xr-xchallenge-276/roger-bell-west/lua/ch-2.lua39
-rwxr-xr-xchallenge-276/roger-bell-west/perl/ch-1.pl24
-rwxr-xr-xchallenge-276/roger-bell-west/perl/ch-2.pl21
-rw-r--r--challenge-276/roger-bell-west/postscript/ch-1.ps97
-rw-r--r--challenge-276/roger-bell-west/postscript/ch-2.ps103
-rwxr-xr-xchallenge-276/roger-bell-west/python/ch-1.py21
-rwxr-xr-xchallenge-276/roger-bell-west/python/ch-2.py22
-rwxr-xr-xchallenge-276/roger-bell-west/raku/ch-1.p613
-rwxr-xr-xchallenge-276/roger-bell-west/raku/ch-2.p617
-rwxr-xr-xchallenge-276/roger-bell-west/ruby/ch-1.rb23
-rwxr-xr-xchallenge-276/roger-bell-west/ruby/ch-2.rb25
-rwxr-xr-xchallenge-276/roger-bell-west/rust/ch-1.rs20
-rwxr-xr-xchallenge-276/roger-bell-west/rust/ch-2.rs17
-rw-r--r--challenge-276/roger-bell-west/scala/ch-1.scala62
-rw-r--r--challenge-276/roger-bell-west/scala/ch-2.scala27
-rw-r--r--challenge-276/roger-bell-west/tests.json28
23 files changed, 829 insertions, 0 deletions
diff --git a/challenge-276/roger-bell-west/crystal/ch-1.cr b/challenge-276/roger-bell-west/crystal/ch-1.cr
new file mode 100755
index 0000000000..ec0beec950
--- /dev/null
+++ b/challenge-276/roger-bell-west/crystal/ch-1.cr
@@ -0,0 +1,18 @@
+#! /usr/bin/crystal
+
+def completeday(a)
+ return a.combinations(2).select{|c| (c[0] + c[1]) % 24 == 0}.size
+end
+
+require "spec"
+describe "completeday" do
+ it "test_ex1" do
+ completeday([12, 12, 30, 24, 24]).should eq 2
+ end
+ it "test_ex2" do
+ completeday([72, 48, 24, 5]).should eq 3
+ end
+ it "test_ex3" do
+ completeday([12, 18, 24]).should eq 0
+ end
+end
diff --git a/challenge-276/roger-bell-west/crystal/ch-2.cr b/challenge-276/roger-bell-west/crystal/ch-2.cr
new file mode 100755
index 0000000000..209b4626d8
--- /dev/null
+++ b/challenge-276/roger-bell-west/crystal/ch-2.cr
@@ -0,0 +1,20 @@
+#! /usr/bin/crystal
+
+def maximumfrequency(a)
+ c = Hash(Int32, Int32).new(default_value: 0)
+ a.each do |w|
+ c[w] += 1
+ end
+ mx = c.values.max
+ return c.values.select{|v| v == mx}.size * mx
+end
+
+require "spec"
+describe "maximumfrequency" do
+ it "test_ex1" do
+ maximumfrequency([1, 2, 2, 4, 1, 5]).should eq 4
+ end
+ it "test_ex2" do
+ maximumfrequency([1, 2, 3, 4, 5]).should eq 5
+ end
+end
diff --git a/challenge-276/roger-bell-west/javascript/ch-1.js b/challenge-276/roger-bell-west/javascript/ch-1.js
new file mode 100755
index 0000000000..684f9494eb
--- /dev/null
+++ b/challenge-276/roger-bell-west/javascript/ch-1.js
@@ -0,0 +1,59 @@
+#! /usr/bin/node
+
+"use strict"
+
+function combinations(arr, k) {
+ let c = [];
+ for (let i = 0; i < k; i++) {
+ c.push(i);
+ }
+ c.push(arr.length);
+ c.push(0);
+ let out = [];
+ while (true) {
+ let inner = [];
+ for (let i = k-1; i >= 0; i--) {
+ inner.push(arr[c[i]]);
+ }
+ out.push(inner);
+ let j = 0;
+ while (c[j] + 1 == c[j + 1]) {
+ c[j] = j;
+ j += 1;
+ }
+ if (j >= k) {
+ break;
+ }
+ c[j] += 1;
+ }
+ return out;
+}
+
+function completeday(a) {
+ let ct = 0;
+ combinations(a, 2).forEach((c) => {
+ if ((c[0] + c[1]) % 24 == 0) {
+ ct += 1;
+ }
+ });
+ return ct;
+}
+
+if (completeday([12, 12, 30, 24, 24]) == 2) {
+ process.stdout.write("Pass");
+} else {
+ process.stdout.write("FAIL");
+}
+process.stdout.write(" ");
+if (completeday([72, 48, 24, 5]) == 3) {
+ process.stdout.write("Pass");
+} else {
+ process.stdout.write("FAIL");
+}
+process.stdout.write(" ");
+if (completeday([12, 18, 24]) == 0) {
+ process.stdout.write("Pass");
+} else {
+ process.stdout.write("FAIL");
+}
+process.stdout.write("\n");
diff --git a/challenge-276/roger-bell-west/javascript/ch-2.js b/challenge-276/roger-bell-west/javascript/ch-2.js
new file mode 100755
index 0000000000..7d3490d278
--- /dev/null
+++ b/challenge-276/roger-bell-west/javascript/ch-2.js
@@ -0,0 +1,29 @@
+#! /usr/bin/node
+
+"use strict"
+
+function maximumfrequency(a) {
+ let c = new Map;
+ for (let w of a) {
+ if (c.has(w)) {
+ c.set(w, c.get(w) + 1);
+ } else {
+ c.set(w, 1);
+ }
+ }
+ const mx = Math.max(...c.values());
+ return mx * [...c.values()].filter(v => v == mx).length;
+}
+
+if (maximumfrequency([1, 2, 2, 4, 1, 5]) == 4) {
+ process.stdout.write("Pass");
+} else {
+ process.stdout.write("FAIL");
+}
+process.stdout.write(" ");
+if (maximumfrequency([1, 2, 3, 4, 5]) == 5) {
+ process.stdout.write("Pass");
+} else {
+ process.stdout.write("FAIL");
+}
+process.stdout.write("\n");
diff --git a/challenge-276/roger-bell-west/kotlin/ch-1.kt b/challenge-276/roger-bell-west/kotlin/ch-1.kt
new file mode 100644
index 0000000000..912f858a21
--- /dev/null
+++ b/challenge-276/roger-bell-west/kotlin/ch-1.kt
@@ -0,0 +1,59 @@
+fun combinations(arr: List<Int>, k: Int): List<List<Int>> {
+ var c = ArrayList<Int>()
+ for (i in 0 .. k-1) {
+ c.add(i)
+ }
+ c.add(arr.size)
+ c.add(0)
+ var out = ArrayList<List<Int>>()
+ while (true) {
+ var inner = ArrayList<Int>()
+ for (i in k-1 downTo 0) {
+ inner.add(arr[c[i]])
+ }
+ out.add(inner.toList())
+ var j = 0
+ while (c[j] + 1 == c[j + 1]) {
+ c[j] = j
+ j += 1
+ }
+ if (j >= k) {
+ break
+ }
+ c[j] += 1
+ }
+ return out.toList()
+}
+
+fun completeday(a: List<Int>): Int {
+ var ct = 0
+ for (c in combinations(a, 2)) {
+ if ((c[0] + c[1]) % 24 == 0) {
+ ct += 1
+ }
+ }
+ return ct
+}
+
+fun main() {
+
+ if (completeday(listOf(12, 12, 30, 24, 24)) == 2) {
+ print("Pass")
+ } else {
+ print("Fail")
+ }
+ print(" ")
+ if (completeday(listOf(72, 48, 24, 5)) == 3) {
+ print("Pass")
+ } else {
+ print("Fail")
+ }
+ print(" ")
+ if (completeday(listOf(12, 18, 24)) == 0) {
+ print("Pass")
+ } else {
+ print("Fail")
+ }
+ println("")
+
+}
diff --git a/challenge-276/roger-bell-west/kotlin/ch-2.kt b/challenge-276/roger-bell-west/kotlin/ch-2.kt
new file mode 100644
index 0000000000..0a0134222b
--- /dev/null
+++ b/challenge-276/roger-bell-west/kotlin/ch-2.kt
@@ -0,0 +1,25 @@
+fun maximumfrequency(a: List<Int>): Int {
+ var c = mutableMapOf<Int, Int>().withDefault({0})
+ for (w in a) {
+ c.set(w, c.getValue(w) + 1)
+ }
+ val mx = c.values.maxOrNull()!!
+ return mx * c.values.filter{it == mx}.size
+}
+
+fun main() {
+
+ if (maximumfrequency(listOf(1, 2, 2, 4, 1, 5)) == 4) {
+ print("Pass")
+ } else {
+ print("Fail")
+ }
+ print(" ")
+ if (maximumfrequency(listOf(1, 2, 3, 4, 5)) == 5) {
+ print("Pass")
+ } else {
+ print("Fail")
+ }
+ println("")
+
+}
diff --git a/challenge-276/roger-bell-west/lua/ch-1.lua b/challenge-276/roger-bell-west/lua/ch-1.lua
new file mode 100755
index 0000000000..932cdc80ad
--- /dev/null
+++ b/challenge-276/roger-bell-west/lua/ch-1.lua
@@ -0,0 +1,60 @@
+#! /usr/bin/lua
+
+function combinations(arr, k)
+ local c = {}
+ for i = 1, k do
+ table.insert(c, i)
+ end
+ table.insert(c, #arr + 1)
+ table.insert(c, 0)
+ local out = {}
+ while true do
+ local inner = {}
+ for i = k, 1, -1 do
+ table.insert(inner, arr[c[i]])
+ end
+ table.insert(out, inner)
+ local j = 1
+ while c[j] + 1 == c[j + 1] do
+ c[j] = j
+ j = j + 1
+ end
+ if j > k then
+ break
+ end
+ c[j] = c[j] + 1
+ end
+ return ipairs(out)
+end
+
+function completeday(a)
+ local out = 0
+ for _, c in combinations(a, 2) do
+ if (c[1] + c[2]) % 24 == 0 then
+ out = out + 1
+ end
+ end
+ return out
+end
+
+if completeday({12, 12, 30, 24, 24}) == 2 then
+ io.write("Pass")
+else
+ io.write("FAIL")
+end
+io.write(" ")
+
+if completeday({72, 48, 24, 5}) == 3 then
+ io.write("Pass")
+else
+ io.write("FAIL")
+end
+io.write(" ")
+
+if completeday({12, 18, 24}) == 0 then
+ io.write("Pass")
+else
+ io.write("FAIL")
+end
+print("")
+
diff --git a/challenge-276/roger-bell-west/lua/ch-2.lua b/challenge-276/roger-bell-west/lua/ch-2.lua
new file mode 100755
index 0000000000..2ca6b9ee7c
--- /dev/null
+++ b/challenge-276/roger-bell-west/lua/ch-2.lua
@@ -0,0 +1,39 @@
+#! /usr/bin/lua
+
+function maximumfrequency(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 v = {}
+ for _, n in pairs(c) do
+ table.insert(v, n)
+ end
+ local mx = math.max(table.unpack(v))
+ local out = 0
+ for _, n in ipairs(v) do
+ if n == mx then
+ out = out + mx
+ end
+ end
+ return out
+end
+
+if maximumfrequency({1, 2, 2, 4, 1, 5}) == 4 then
+ io.write("Pass")
+else
+ io.write("FAIL")
+end
+io.write(" ")
+
+if maximumfrequency({1, 2, 3, 4, 5}) == 5 then
+ io.write("Pass")
+else
+ io.write("FAIL")
+end
+print("")
+
diff --git a/challenge-276/roger-bell-west/perl/ch-1.pl b/challenge-276/roger-bell-west/perl/ch-1.pl
new file mode 100755
index 0000000000..bc8c5246ec
--- /dev/null
+++ b/challenge-276/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(completeday([12, 12, 30, 24, 24]), 2, 'example 1');
+is(completeday([72, 48, 24, 5]), 3, 'example 2');
+is(completeday([12, 18, 24]), 0, 'example 3');
+
+use Algorithm::Combinatorics qw(combinations);
+
+sub completeday($a) {
+ my $out = 0;
+ my $ip = combinations($a, 2);
+ while (my $c = $ip->next) {
+ if (($c->[0] + $c->[1]) % 24 == 0) {
+ $out++;
+ }
+ }
+ return $out;
+}
diff --git a/challenge-276/roger-bell-west/perl/ch-2.pl b/challenge-276/roger-bell-west/perl/ch-2.pl
new file mode 100755
index 0000000000..1095024106
--- /dev/null
+++ b/challenge-276/roger-bell-west/perl/ch-2.pl
@@ -0,0 +1,21 @@
+#! /usr/bin/perl
+
+use strict;
+use warnings;
+use experimental 'signatures';
+
+use Test::More tests => 2;
+
+is(maximumfrequency([1, 2, 2, 4, 1, 5]), 4, 'example 1');
+is(maximumfrequency([1, 2, 3, 4, 5]), 5, 'example 2');
+
+use List::Util qw(max);
+
+sub maximumfrequency($a) {
+ my %c;
+ foreach my $n (@{$a}) {
+ $c{$n}++;
+ }
+ my $m = max(values %c);
+ return $m * scalar grep {$_ == $m} values %c;
+}
diff --git a/challenge-276/roger-bell-west/postscript/ch-1.ps b/challenge-276/roger-bell-west/postscript/ch-1.ps
new file mode 100644
index 0000000000..0acf9347b5
--- /dev/null
+++ b/challenge-276/roger-bell-west/postscript/ch-1.ps
@@ -0,0 +1,97 @@
+%!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
+
+/combinations {
+ 4 dict begin
+ /k exch def
+ /arr exch def
+ /c [
+ 0 1 k 1 sub { } for
+ arr length
+ 0
+ ] def
+ [
+ {
+ [
+ k 1 sub -1 0 {
+ c exch get arr exch get
+ } for
+ ]
+ /j 0 def
+ {
+ c j get 1 add c j 1 add get ne {
+ exit
+ } if
+ c j j put
+ /j j 1 add def
+ } loop
+ j k ge {
+ exit
+ } if
+ c j c j get 1 add put
+ } loop
+ ]
+ end
+} bind def
+
+/test.start {
+ print (:) print
+ /test.pass 0 def
+ /test.count 0 def
+} bind def
+
+/filter { % array proc(bool) -> array
+ 1 dict begin
+ /p exch def
+ [ exch
+ {
+ dup p not
+ {
+ pop
+ } if
+ } forall
+ ]
+ end
+} 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
+
+/completeday {
+ 2 combinations {
+ aload pop
+ add 24 mod 0 eq
+ } filter length
+} bind def
+
+(completeday) test.start
+[12 12 30 24 24] completeday 2 eq test
+[72 48 24 5] completeday 3 eq test
+[12 18 24] completeday 0 eq test
+test.end
diff --git a/challenge-276/roger-bell-west/postscript/ch-2.ps b/challenge-276/roger-bell-west/postscript/ch-2.ps
new file mode 100644
index 0000000000..740adc8b4d
--- /dev/null
+++ b/challenge-276/roger-bell-west/postscript/ch-2.ps
@@ -0,0 +1,103 @@
+%!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
+
+/listmax {
+ { max } reduce
+} bind def
+
+/reduce { % array proc -> value
+ 2 dict begin
+ /p exch def
+ /a exch def
+ a 0 get
+ 1 1 a length 1 sub {
+ a exch get
+ p
+ } for
+ end
+} bind def
+
+/filter { % array proc(bool) -> array
+ 1 dict begin
+ /p exch def
+ [ exch
+ {
+ dup p not
+ {
+ pop
+ } if
+ } forall
+ ]
+ end
+} bind def
+
+/dget {
+ 3 1 roll
+ 2 copy
+ known {
+ get exch pop
+ } {
+ pop pop
+ } ifelse
+} bind def
+
+/values { % dict -> array of dict values
+ [ exch
+ {
+ exch pop
+ } 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
+
+/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
+
+
+% end included library code
+
+/maximumfrequency {
+ 0 dict begin
+ /c 0 dict def
+ {
+ c exch
+ 2 copy
+ 0 dget 1 add put
+ } forall
+ /mx c values listmax def
+ c values { mx eq } filter length mx mul
+ end
+} bind def
+
+(maximumfrequency) test.start
+[1 2 2 4 1 5] maximumfrequency 4 eq test
+[1 2 3 4 5] maximumfrequency 5 eq test
+test.end
diff --git a/challenge-276/roger-bell-west/python/ch-1.py b/challenge-276/roger-bell-west/python/ch-1.py
new file mode 100755
index 0000000000..27ea589f31
--- /dev/null
+++ b/challenge-276/roger-bell-west/python/ch-1.py
@@ -0,0 +1,21 @@
+#! /usr/bin/python3
+
+from itertools import combinations
+
+def completeday(a):
+ return len([t for t in combinations(a, 2) if (t[0] + t[1]) % 24 == 0])
+
+import unittest
+
+class TestCompleteday(unittest.TestCase):
+
+ def test_ex1(self):
+ self.assertEqual(completeday([12, 12, 30, 24, 24]), 2, 'example 1')
+
+ def test_ex2(self):
+ self.assertEqual(completeday([72, 48, 24, 5]), 3, 'example 2')
+
+ def test_ex3(self):
+ self.assertEqual(completeday([12, 18, 24]), 0, 'example 3')
+
+unittest.main()
diff --git a/challenge-276/roger-bell-west/python/ch-2.py b/challenge-276/roger-bell-west/python/ch-2.py
new file mode 100755
index 0000000000..65e5d86b7b
--- /dev/null
+++ b/challenge-276/roger-bell-west/python/ch-2.py
@@ -0,0 +1,22 @@
+#! /usr/bin/python3
+
+from collections import defaultdict
+
+def maximumfrequency(a):
+ c = defaultdict(lambda: 0)
+ for n in a:
+ c[n] += 1
+ mx = max(c.values())
+ return mx * len([v for v in c.values() if v == mx])
+
+import unittest
+
+class TestMaximumfrequency(unittest.TestCase):
+
+ def test_ex1(self):
+ self.assertEqual(maximumfrequency([1, 2, 2, 4, 1, 5]), 4, 'example 1')
+
+ def test_ex2(self):
+ self.assertEqual(maximumfrequency([1, 2, 3, 4, 5]), 5, 'example 2')
+
+unittest.main()
diff --git a/challenge-276/roger-bell-west/raku/ch-1.p6 b/challenge-276/roger-bell-west/raku/ch-1.p6
new file mode 100755
index 0000000000..78b49d09c4
--- /dev/null
+++ b/challenge-276/roger-bell-west/raku/ch-1.p6
@@ -0,0 +1,13 @@
+#! /usr/bin/raku
+
+use Test;
+
+plan 3;
+
+is(completeday([12, 12, 30, 24, 24]), 2, 'example 1');
+is(completeday([72, 48, 24, 5]), 3, 'example 2');
+is(completeday([12, 18, 24]), 0, 'example 3');
+
+sub completeday(@a) {
+ return @a.combinations(2).grep({($_[0] + $_[1]) % 24 == 0 }).elems;
+}
diff --git a/challenge-276/roger-bell-west/raku/ch-2.p6 b/challenge-276/roger-bell-west/raku/ch-2.p6
new file mode 100755
index 0000000000..6a15c5434b
--- /dev/null
+++ b/challenge-276/roger-bell-west/raku/ch-2.p6
@@ -0,0 +1,17 @@
+#! /usr/bin/raku
+
+use Test;
+
+plan 2;
+
+is(maximumfrequency([1, 2, 2, 4, 1, 5]), 4, 'example 1');
+is(maximumfrequency([1, 2, 3, 4, 5]), 5, 'example 2');
+
+sub maximumfrequency(@a) {
+ my %c;
+ for @a -> $n {
+ %c{$n}++;
+ }
+ my $mx = %c.values.max;
+ return $mx * %c.values.grep({$_ == $mx}).elems;
+}
diff --git a/challenge-276/roger-bell-west/ruby/ch-1.rb b/challenge-276/roger-bell-west/ruby/ch-1.rb
new file mode 100755
index 0000000000..106f8ddcc8
--- /dev/null
+++ b/challenge-276/roger-bell-west/ruby/ch-1.rb
@@ -0,0 +1,23 @@
+#! /usr/bin/ruby
+
+def completeday(a)
+ return a.combination(2).find_all{|c| (c[0] + c[1]) % 24 == 0}.length
+end
+
+require 'test/unit'
+
+class TestCompleteday < Test::Unit::TestCase
+
+ def test_ex1
+ assert_equal(2, completeday([12, 12, 30, 24, 24]))
+ end
+
+ def test_ex2
+ assert_equal(3, completeday([72, 48, 24, 5]))
+ end
+
+ def test_ex3
+ assert_equal(0, completeday([12, 18, 24]))
+ end
+
+end
diff --git a/challenge-276/roger-bell-west/ruby/ch-2.rb b/challenge-276/roger-bell-west/ruby/ch-2.rb
new file mode 100755
index 0000000000..4b2dc1f3bf
--- /dev/null
+++ b/challenge-276/roger-bell-west/ruby/ch-2.rb
@@ -0,0 +1,25 @@
+#! /usr/bin/ruby
+
+def maximumfrequency(a)
+ c = Hash.new
+ c.default = 0
+ a.each do |w|
+ c[w] += 1
+ end
+ mx = c.values.max
+ return c.values.find_all{|v| v == mx}.length * mx
+end
+
+require 'test/unit'
+
+class TestMaximumfrequency < Test::Unit::TestCase
+
+ def test_ex1
+ assert_equal(4, maximumfrequency([1, 2, 2, 4, 1, 5]))
+ end
+
+ def test_ex2
+ assert_equal(5, maximumfrequency([1, 2, 3, 4, 5]))
+ end
+
+end
diff --git a/challenge-276/roger-bell-west/rust/ch-1.rs b/challenge-276/roger-bell-west/rust/ch-1.rs
new file mode 100755
index 0000000000..0ff041538d
--- /dev/null
+++ b/challenge-276/roger-bell-west/rust/ch-1.rs
@@ -0,0 +1,20 @@
+use itertools::Itertools;
+
+#[test]
+fn test_ex1() {
+ assert_eq!(completeday(vec![12, 12, 30, 24, 24]), 2);
+}
+
+#[test]
+fn test_ex2() {
+ assert_eq!(completeday(vec![72, 48, 24, 5]), 3);
+}
+
+#[test]
+fn test_ex3() {
+ assert_eq!(completeday(vec![12, 18, 24]), 0);
+}
+
+fn completeday(a: Vec<u32>) -> usize {
+ a.iter().combinations(2).filter(|c| (c[0] + c[1]) % 24 == 0).count()
+}
diff --git a/challenge-276/roger-bell-west/rust/ch-2.rs b/challenge-276/roger-bell-west/rust/ch-2.rs
new file mode 100755
index 0000000000..e02395e3d1
--- /dev/null
+++ b/challenge-276/roger-bell-west/rust/ch-2.rs
@@ -0,0 +1,17 @@
+use counter::Counter;
+
+#[test]
+fn test_ex1() {
+ assert_eq!(maximumfrequency(vec![1, 2, 2, 4, 1, 5]), 4);
+}
+
+#[test]
+fn test_ex2() {
+ assert_eq!(maximumfrequency(vec![1, 2, 3, 4, 5]), 5);
+}
+
+fn maximumfrequency(a: Vec<u32>) -> usize {
+ let c = a.iter().collect::<Counter<_>>();
+ let mx = c.most_common_ordered()[0].1;
+ c.iter().filter(|(_k, v)| **v == mx).count() * mx
+}
diff --git a/challenge-276/roger-bell-west/scala/ch-1.scala b/challenge-276/roger-bell-west/scala/ch-1.scala
new file mode 100644
index 0000000000..14c357eb14
--- /dev/null
+++ b/challenge-276/roger-bell-west/scala/ch-1.scala
@@ -0,0 +1,62 @@
+import scala.collection.mutable.ListBuffer
+
+object Completeday {
+ def combinations(arr: List[Int], k: Int): List[List[Int]] = {
+ var c = new ListBuffer[Int]()
+ for (i <- 0 until k) {
+ c += i
+ }
+ c += arr.length
+ c += 0
+ var out = new ListBuffer[List[Int]]()
+ var cont = true
+ while (cont) {
+ var inner = new ListBuffer[Int]()
+ for (i <- List.range(k-1, -1, -1)) {
+ inner += arr(c(i))
+ }
+ out += inner.toList
+ var j = 0
+ while (c(j) + 1 == c(j + 1)) {
+ c(j) = j
+ j += 1
+ }
+ if (j >= k) {
+ cont = false
+ } else {
+ c(j) += 1
+ }
+ }
+ return out.toList
+ }
+ def completeday(a: List[Int]): Int = {
+ var ct = 0
+ for (c <- combinations(a, 2)) {
+ if ((c(0) + c(1)) % 24 == 0) {
+ ct += 1
+ }
+ }
+ return ct
+ }
+ def main(args: Array[String]) {
+ if (completeday(List(12, 12, 30, 24, 24)) == 2) {
+ print("Pass")
+ } else {
+ print("Fail")
+ }
+ print(" ")
+ if (completeday(List(72, 48, 24, 5)) == 3) {
+ print("Pass")
+ } else {
+ print("Fail")
+ }
+ print(" ")
+ if (completeday(List(12, 18, 24)) == 0) {
+ print("Pass")
+ } else {
+ print("Fail")
+ }
+ println("")
+
+ }
+}
diff --git a/challenge-276/roger-bell-west/scala/ch-2.scala b/challenge-276/roger-bell-west/scala/ch-2.scala
new file mode 100644
index 0000000000..c9217d0677
--- /dev/null
+++ b/challenge-276/roger-bell-west/scala/ch-2.scala
@@ -0,0 +1,27 @@
+import scala.collection.mutable
+
+object Maximumfrequency {
+ def maximumfrequency(a: List[Int]): Int = {
+ var c = mutable.Map.empty[Int, Int].withDefaultValue(0)
+ for (w <- a) {
+ c += (w -> (c(w) + 1))
+ }
+ val mx = c.values.max
+ return mx * c.values.filter(v => v == mx).size
+ }
+ def main(args: Array[String]) {
+ if (maximumfrequency(List(1, 2, 2, 4, 1, 5)) == 4) {
+ print("Pass")
+ } else {
+ print("Fail")
+ }
+ print(" ")
+ if (maximumfrequency(List(1, 2, 3, 4, 5)) == 5) {
+ print("Pass")
+ } else {
+ print("Fail")
+ }
+ println("")
+
+ }
+}
diff --git a/challenge-276/roger-bell-west/tests.json b/challenge-276/roger-bell-west/tests.json
new file mode 100644
index 0000000000..af1203b897
--- /dev/null
+++ b/challenge-276/roger-bell-west/tests.json
@@ -0,0 +1,28 @@
+{
+ "ch-1" : [
+ {
+ "function" : "completeday",
+ "arguments" : [ 12, 12, 30, 24, 24 ],
+ "result" : 2
+ },
+ {
+ "arguments" : [ 72, 48, 24, 5 ],
+ "result" : 3
+ },
+ {
+ "arguments" : [ 12, 18, 24 ],
+ "result" : 0
+ }
+ ],
+ "ch-2" : [
+ {
+ "function" : "maximumfrequency",
+ "arguments" : [ 1, 2, 2, 4, 1, 5 ],
+ "result" : 4
+ },
+ {
+ "arguments" : [1, 2, 3, 4, 5 ],
+ "result" : 5
+ }
+ ]
+}