aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRoger Bell_West <roger@firedrake.org>2025-07-29 13:40:52 +0100
committerRoger Bell_West <roger@firedrake.org>2025-07-29 13:40:52 +0100
commite1b54fc04d713b8d67bae3a157f57fc613a4357f (patch)
tree8b4f632929e556f12b8a4a26c6ab6d97664f380d
parent1ff2c9796a511d63231d3757acb27e4046a91fb2 (diff)
downloadperlweeklychallenge-club-e1b54fc04d713b8d67bae3a157f57fc613a4357f.tar.gz
perlweeklychallenge-club-e1b54fc04d713b8d67bae3a157f57fc613a4357f.tar.bz2
perlweeklychallenge-club-e1b54fc04d713b8d67bae3a157f57fc613a4357f.zip
RogerBW solutions for challenge no. 332
-rwxr-xr-xchallenge-332/roger-bell-west/crystal/ch-1.cr18
-rwxr-xr-xchallenge-332/roger-bell-west/crystal/ch-2.cr27
-rwxr-xr-xchallenge-332/roger-bell-west/javascript/ch-1.js26
-rwxr-xr-xchallenge-332/roger-bell-west/javascript/ch-2.js43
-rw-r--r--challenge-332/roger-bell-west/kotlin/ch-1.kt26
-rw-r--r--challenge-332/roger-bell-west/kotlin/ch-2.kt35
-rwxr-xr-xchallenge-332/roger-bell-west/lua/ch-1.lua87
-rwxr-xr-xchallenge-332/roger-bell-west/lua/ch-2.lua55
-rwxr-xr-xchallenge-332/roger-bell-west/perl/ch-1.pl15
-rwxr-xr-xchallenge-332/roger-bell-west/perl/ch-2.pl22
-rw-r--r--challenge-332/roger-bell-west/postscript/ch-1.ps169
-rw-r--r--challenge-332/roger-bell-west/postscript/ch-2.ps83
-rwxr-xr-xchallenge-332/roger-bell-west/python/ch-1.py19
-rwxr-xr-xchallenge-332/roger-bell-west/python/ch-2.py24
-rwxr-xr-xchallenge-332/roger-bell-west/raku/ch-1.p613
-rwxr-xr-xchallenge-332/roger-bell-west/raku/ch-2.p615
-rwxr-xr-xchallenge-332/roger-bell-west/ruby/ch-1.rb23
-rwxr-xr-xchallenge-332/roger-bell-west/ruby/ch-2.rb33
-rwxr-xr-xchallenge-332/roger-bell-west/rust/ch-1.rs24
-rwxr-xr-xchallenge-332/roger-bell-west/rust/ch-2.rs21
-rw-r--r--challenge-332/roger-bell-west/scala/ch-1.scala27
-rw-r--r--challenge-332/roger-bell-west/scala/ch-2.scala38
-rw-r--r--challenge-332/roger-bell-west/tests.json32
-rw-r--r--challenge-332/roger-bell-west/typst/ch-1.typ39
-rw-r--r--challenge-332/roger-bell-west/typst/ch-2.typ30
25 files changed, 944 insertions, 0 deletions
diff --git a/challenge-332/roger-bell-west/crystal/ch-1.cr b/challenge-332/roger-bell-west/crystal/ch-1.cr
new file mode 100755
index 0000000000..06b1ce1e51
--- /dev/null
+++ b/challenge-332/roger-bell-west/crystal/ch-1.cr
@@ -0,0 +1,18 @@
+#! /usr/bin/crystal
+
+def binarydate(a)
+ a.split("-").map{|n| n.to_i.to_s(2)}.join("-")
+end
+
+require "spec"
+describe "binarydate" do
+ it "test_ex1" do
+ binarydate("2025-07-26").should eq "11111101001-111-11010"
+ end
+ it "test_ex2" do
+ binarydate("2000-02-02").should eq "11111010000-10-10"
+ end
+ it "test_ex3" do
+ binarydate("2024-12-31").should eq "11111101000-1100-11111"
+ end
+end
diff --git a/challenge-332/roger-bell-west/crystal/ch-2.cr b/challenge-332/roger-bell-west/crystal/ch-2.cr
new file mode 100755
index 0000000000..e2c016bd69
--- /dev/null
+++ b/challenge-332/roger-bell-west/crystal/ch-2.cr
@@ -0,0 +1,27 @@
+#! /usr/bin/crystal
+
+def counterify(a)
+ cc = Hash(Char, Int32).new(default_value: 0)
+ a.each do |x|
+ cc[x] += 1
+ end
+ return cc
+end
+
+def oddletters(a)
+ c = counterify(a.chars)
+ c.values.all? { |v| v % 2 == 1 }
+end
+
+require "spec"
+describe "oddletters" do
+ it "test_ex1" do
+ oddletters("weekly").should eq false
+ end
+ it "test_ex2" do
+ oddletters("perl").should eq true
+ end
+ it "test_ex3" do
+ oddletters("challenge").should eq false
+ end
+end
diff --git a/challenge-332/roger-bell-west/javascript/ch-1.js b/challenge-332/roger-bell-west/javascript/ch-1.js
new file mode 100755
index 0000000000..9e43737bc9
--- /dev/null
+++ b/challenge-332/roger-bell-west/javascript/ch-1.js
@@ -0,0 +1,26 @@
+#! /usr/bin/node
+
+"use strict"
+
+function binarydate(a) {
+ return a.split("-").map(n => (n >>> 0).toString(2)).join("-");
+}
+
+if (binarydate('2025-07-26') == '11111101001-111-11010') {
+ process.stdout.write("Pass");
+} else {
+ process.stdout.write("FAIL");
+}
+process.stdout.write(" ");
+if (binarydate('2000-02-02') == '11111010000-10-10') {
+ process.stdout.write("Pass");
+} else {
+ process.stdout.write("FAIL");
+}
+process.stdout.write(" ");
+if (binarydate('2024-12-31') == '11111101000-1100-11111') {
+ process.stdout.write("Pass");
+} else {
+ process.stdout.write("FAIL");
+}
+process.stdout.write("\n");
diff --git a/challenge-332/roger-bell-west/javascript/ch-2.js b/challenge-332/roger-bell-west/javascript/ch-2.js
new file mode 100755
index 0000000000..b23d481d2f
--- /dev/null
+++ b/challenge-332/roger-bell-west/javascript/ch-2.js
@@ -0,0 +1,43 @@
+#! /usr/bin/node
+
+"use strict"
+
+function counterify(a) {
+ let cc = new Map;
+ for (let x of a) {
+ if (!cc.has(x)) {
+ cc.set(x, 0);
+ }
+ cc.set(x, cc.get(x) + 1);
+ }
+ return cc;
+}
+
+function oddletters(a) {
+ const c = counterify(a);
+ for (let v of c.values()) {
+ if (v % 2 == 0) {
+ return false;
+ }
+ }
+ return true;
+}
+
+if (!oddletters('weekly')) {
+ process.stdout.write("Pass");
+} else {
+ process.stdout.write("FAIL");
+}
+process.stdout.write(" ");
+if (oddletters('perl')) {
+ process.stdout.write("Pass");
+} else {
+ process.stdout.write("FAIL");
+}
+process.stdout.write(" ");
+if (!oddletters('challenge')) {
+ process.stdout.write("Pass");
+} else {
+ process.stdout.write("FAIL");
+}
+process.stdout.write("\n");
diff --git a/challenge-332/roger-bell-west/kotlin/ch-1.kt b/challenge-332/roger-bell-west/kotlin/ch-1.kt
new file mode 100644
index 0000000000..e6f516621c
--- /dev/null
+++ b/challenge-332/roger-bell-west/kotlin/ch-1.kt
@@ -0,0 +1,26 @@
+fun binarydate(a: String): String {
+ return a.split("-").map{it.toInt().toString(2)}.joinToString("-")
+}
+
+fun main() {
+
+ if (binarydate("2025-07-26") == "11111101001-111-11010") {
+ print("Pass")
+ } else {
+ print("Fail")
+ }
+ print(" ")
+ if (binarydate("2000-02-02") == "11111010000-10-10") {
+ print("Pass")
+ } else {
+ print("Fail")
+ }
+ print(" ")
+ if (binarydate("2024-12-31") == "11111101000-1100-11111") {
+ print("Pass")
+ } else {
+ print("Fail")
+ }
+ println("")
+
+}
diff --git a/challenge-332/roger-bell-west/kotlin/ch-2.kt b/challenge-332/roger-bell-west/kotlin/ch-2.kt
new file mode 100644
index 0000000000..1e281b2062
--- /dev/null
+++ b/challenge-332/roger-bell-west/kotlin/ch-2.kt
@@ -0,0 +1,35 @@
+fun counterify(a: List<Char>): Map<Char, Int> {
+ var cc = mutableMapOf<Char, Int>().withDefault({0})
+ for (x in a) {
+ cc.set(x, cc.getValue(x) + 1)
+ }
+ return cc
+}
+
+fun oddletters(a: String): Boolean {
+ val c = counterify(a.toCharArray().toList());
+ return c.values.all{v -> v % 2 == 1}
+}
+
+fun main() {
+
+ if (!oddletters("weekly")) {
+ print("Pass")
+ } else {
+ print("Fail")
+ }
+ print(" ")
+ if (oddletters("perl")) {
+ print("Pass")
+ } else {
+ print("Fail")
+ }
+ print(" ")
+ if (!oddletters("challenge")) {
+ print("Pass")
+ } else {
+ print("Fail")
+ }
+ println("")
+
+}
diff --git a/challenge-332/roger-bell-west/lua/ch-1.lua b/challenge-332/roger-bell-west/lua/ch-1.lua
new file mode 100755
index 0000000000..c90cecb21d
--- /dev/null
+++ b/challenge-332/roger-bell-west/lua/ch-1.lua
@@ -0,0 +1,87 @@
+#! /usr/bin/lua
+
+function splits(inputstr, sep)
+ sep = sep or '%s'
+ local starts = {1}
+ local ends = {}
+ local n = 1
+ while true do
+ local fs, fe = string.find(inputstr, sep, n)
+ if fs == nil then
+ break
+ end
+ table.insert(ends, fs - 1)
+ table.insert(starts, fe + 1)
+ n = fe + 1
+ end
+ table.insert(ends, #inputstr)
+ local t = {}
+ for i = 1, #starts do
+ local s = starts[i]
+ local e = ends[i]
+ if e >= s then
+ table.insert(t, string.sub(inputstr, s, e))
+ end
+ end
+ return t
+end
+
+function joins(t,pad)
+ local out=""
+ local later = false
+ for k,v in pairs(t) do
+ if later then
+ out = out .. pad
+ end
+ out = out .. v
+ later = true
+ end
+ return out
+end
+
+function tobinary(n)
+ if n == 0 then
+ return "0"
+ end
+ local t = {}
+ local m = 0 + n
+ while m > 0 do
+ if (m & 1) > 0 then
+ table.insert(t, 1, "1")
+ else
+ table.insert(t, 1, "0")
+ end
+ m = m >> 1
+ end
+ return joins(t, "")
+end
+
+function binarydate(a)
+ local out = {}
+ for _, n in ipairs(splits(a, "-")) do
+ table.insert(out, tobinary(n))
+ end
+ return joins(out, "-")
+end
+
+if binarydate("2025-07-26") == "11111101001-111-11010" then
+ io.write("Pass")
+else
+ io.write("FAIL")
+end
+io.write(" ")
+
+if binarydate("2000-02-02") == "11111010000-10-10" then
+ io.write("Pass")
+else
+ io.write("FAIL")
+end
+io.write(" ")
+
+if binarydate("2024-12-31") == "11111101000-1100-11111" then
+ io.write("Pass")
+else
+ io.write("FAIL")
+end
+print("")
+
diff --git a/challenge-332/roger-bell-west/lua/ch-2.lua b/challenge-332/roger-bell-west/lua/ch-2.lua
new file mode 100755
index 0000000000..6e1b6a520d
--- /dev/null
+++ b/challenge-332/roger-bell-west/lua/ch-2.lua
@@ -0,0 +1,55 @@
+#! /usr/bin/lua
+
+function split(t)
+ local cl = {}
+ string.gsub(t,
+ "(.)",
+ function(c)
+ table.insert(cl, c)
+ end
+ )
+ return cl
+end
+
+function counterify(a)
+ local cc = {}
+ for _, c in ipairs(a) do
+ if cc[c] == nil then
+ cc[c] = 0
+ end
+ cc[c] = cc[c] + 1
+ end
+ return cc
+end
+
+function oddletters(a)
+ local c = counterify(split(a))
+ for _, v in pairs(c) do
+ if v % 2 == 0 then
+ return false
+ end
+ end
+ return true
+end
+
+if not oddletters("weekly") then
+ io.write("Pass")
+else
+ io.write("FAIL")
+end
+io.write(" ")
+
+if oddletters("perl") then
+ io.write("Pass")
+else
+ io.write("FAIL")
+end
+io.write(" ")
+
+if not oddletters("challenge") then
+ io.write("Pass")
+else
+ io.write("FAIL")
+end
+print("")
+
diff --git a/challenge-332/roger-bell-west/perl/ch-1.pl b/challenge-332/roger-bell-west/perl/ch-1.pl
new file mode 100755
index 0000000000..c43e526375
--- /dev/null
+++ b/challenge-332/roger-bell-west/perl/ch-1.pl
@@ -0,0 +1,15 @@
+#! /usr/bin/perl
+
+use strict;
+use warnings;
+use experimental 'signatures';
+
+use Test::More tests => 3;
+
+is(binarydate('2025-07-26'), '11111101001-111-11010', 'example 1');
+is(binarydate('2000-02-02'), '11111010000-10-10', 'example 2');
+is(binarydate('2024-12-31'), '11111101000-1100-11111', 'example 3');
+
+sub binarydate($a) {
+ join('-', map {sprintf('%b', $_)} split('-', $a));
+}
diff --git a/challenge-332/roger-bell-west/perl/ch-2.pl b/challenge-332/roger-bell-west/perl/ch-2.pl
new file mode 100755
index 0000000000..454c18cacf
--- /dev/null
+++ b/challenge-332/roger-bell-west/perl/ch-2.pl
@@ -0,0 +1,22 @@
+#! /usr/bin/perl
+
+use strict;
+use warnings;
+use experimental 'signatures';
+
+use Test::More tests => 3;
+
+is(oddletters('weekly'), 0, 'example 1');
+is(oddletters('perl'), 1, 'example 2');
+is(oddletters('challenge'), 0, 'example 3');
+
+sub oddletters($a) {
+ my %c;
+ map {$c{$_}++} split '', $a;
+ foreach my $v (values %c) {
+ if ($v % 2 == 0) {
+ return 0;
+ }
+ }
+ return 1;
+}
diff --git a/challenge-332/roger-bell-west/postscript/ch-1.ps b/challenge-332/roger-bell-west/postscript/ch-1.ps
new file mode 100644
index 0000000000..197c74d010
--- /dev/null
+++ b/challenge-332/roger-bell-west/postscript/ch-1.ps
@@ -0,0 +1,169 @@
+%!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.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
+
+/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
+
+
+/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
+
+/map { % array proc -> array
+ 2 dict begin
+ /p exch def
+ [ exch
+ {
+ p
+ } forall
+ ]
+ end
+} bind def
+
+/reverse {
+ 1 dict begin
+ dup length /l exch def
+ [ exch
+ aload pop
+ 2 1 l {
+ -1 roll
+ } for
+ ]
+ end
+} bind def
+
+/strjoin % [(a) (b) (c)] (j) -> (ajbjc)
+{
+ 3 dict begin
+ /j exch def
+ dup 0 get /out exch def
+ /first true def
+ {
+ first {
+ pop
+ /first false def
+ } {
+ out j strconcat
+ exch strconcat
+ /out exch def
+ } ifelse
+ } forall
+ out
+ end
+} bind def
+
+/strconcat % (a) (b) -> (ab)
+{
+ [
+ 3 -1 roll
+ s2a aload length
+ 2 add -1 roll
+ s2a aload pop
+ ] a2s
+} bind def
+
+/strsplit % (ajbjc) (j) -> [ (a) (b) (c) ]
+{
+ 1 dict begin
+ /sep exch def
+ [ exch
+ {
+ dup length 0 eq {
+ pop
+ exit
+ } {
+ sep search {
+ exch pop
+ dup length 0 eq {
+ pop
+ } {
+ exch
+ } ifelse
+ } {
+ ()
+ } ifelse
+ } ifelse
+ } loop
+ ]
+ end
+} bind def
+
+/s2a {
+ [ exch { } forall ]
+} bind def
+
+
+% end included library code
+
+/tobinary {
+ 0 dict begin
+ /m exch def
+ m 0 eq {
+ (0)
+ } {
+ [
+ {
+ m 0 eq {
+ exit
+ } if
+ m 1 and 0 gt {
+ 49
+ } {
+ 48
+ } ifelse
+ /m m -1 bitshift def
+ } loop
+ ] reverse a2s
+ } ifelse
+ end
+} bind def
+
+/binarydate {
+ 0 dict begin
+ (-) strsplit
+ { cvi tobinary } map
+ (-) strjoin
+ end
+} bind def
+
+(binarydate) test.start
+(2025-07-26) binarydate (11111101001-111-11010) eq test
+(2000-02-02) binarydate (11111010000-10-10) eq test
+(2024-12-31) binarydate (11111101000-1100-11111) eq test
+test.end
diff --git a/challenge-332/roger-bell-west/postscript/ch-2.ps b/challenge-332/roger-bell-west/postscript/ch-2.ps
new file mode 100644
index 0000000000..8e9b1daa9d
--- /dev/null
+++ b/challenge-332/roger-bell-west/postscript/ch-2.ps
@@ -0,0 +1,83 @@
+%!PS
+
+% begin included library code
+% see https://codeberg.org/Firedrake/postscript-libraries/
+/all { % [a b] proc -> bool
+ 1 dict begin
+ /p exch def
+ true exch
+ {
+ p not {
+ pop false
+ exit
+ } if
+ } forall
+ end
+} 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
+
+/test.start {
+ print (:) print
+ /test.pass 0 def
+ /test.count 0 def
+} 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
+
+/values { % dict -> array of dict values
+ [ exch
+ {
+ exch pop
+ } forall
+ ]
+} bind def
+
+
+% end included library code
+
+/counterify {
+ 2 dict begin
+ /c 0 dict def
+ {
+ /n exch def
+ c n known {
+ c n 2 copy get 1 add put
+ } {
+ c n 1 put
+ } ifelse
+ } forall
+ c
+ end
+} bind def
+
+/oddletters {
+ counterify values { 2 mod 1 eq } all
+} bind def
+
+(oddletters) test.start
+(weekly) oddletters not test
+(perl) oddletters test
+(challenge) oddletters not test
+test.end
diff --git a/challenge-332/roger-bell-west/python/ch-1.py b/challenge-332/roger-bell-west/python/ch-1.py
new file mode 100755
index 0000000000..bf4a9de2d7
--- /dev/null
+++ b/challenge-332/roger-bell-west/python/ch-1.py
@@ -0,0 +1,19 @@
+#! /usr/bin/python3
+
+def binarydate(a):
+ return "-".join(["{0:b}".format(int(n)) for n in a.split("-")])
+
+import unittest
+
+class TestBinarydate(unittest.TestCase):
+
+ def test_ex1(self):
+ self.assertEqual(binarydate("2025-07-26"), "11111101001-111-11010", 'example 1')
+
+ def test_ex2(self):
+ self.assertEqual(binarydate("2000-02-02"), "11111010000-10-10", 'example 2')
+
+ def test_ex3(self):
+ self.assertEqual(binarydate("2024-12-31"), "11111101000-1100-11111", 'example 3')
+
+unittest.main()
diff --git a/challenge-332/roger-bell-west/python/ch-2.py b/challenge-332/roger-bell-west/python/ch-2.py
new file mode 100755
index 0000000000..02aba2013e
--- /dev/null
+++ b/challenge-332/roger-bell-west/python/ch-2.py
@@ -0,0 +1,24 @@
+#! /usr/bin/python3
+
+from collections import defaultdict
+
+def oddletters(a):
+ c = defaultdict(lambda: 0)
+ for x in a:
+ c[x] += 1
+ return all(x % 2 == 1 for x in c.values())
+
+import unittest
+
+class TestOddletters(unittest.TestCase):
+
+ def test_ex1(self):
+ self.assertEqual(oddletters("weekly"), False, 'example 1')
+
+ def test_ex2(self):
+ self.assertEqual(oddletters("perl"), True, 'example 2')
+
+ def test_ex3(self):
+ self.assertEqual(oddletters("challenge"), False, 'example 3')
+
+unittest.main()
diff --git a/challenge-332/roger-bell-west/raku/ch-1.p6 b/challenge-332/roger-bell-west/raku/ch-1.p6
new file mode 100755
index 0000000000..e329103b16
--- /dev/null
+++ b/challenge-332/roger-bell-west/raku/ch-1.p6
@@ -0,0 +1,13 @@
+#! /usr/bin/raku
+
+use Test;
+
+plan 3;
+
+is(binarydate('2025-07-26'), '11111101001-111-11010', 'example 1');
+is(binarydate('2000-02-02'), '11111010000-10-10', 'example 2');
+is(binarydate('2024-12-31'), '11111101000-1100-11111', 'example 3');
+
+sub binarydate($a) {
+ $a.split('-').map({sprintf('%b', $_)}).join('-');
+}
diff --git a/challenge-332/roger-bell-west/raku/ch-2.p6 b/challenge-332/roger-bell-west/raku/ch-2.p6
new file mode 100755
index 0000000000..42d3308f01
--- /dev/null
+++ b/challenge-332/roger-bell-west/raku/ch-2.p6
@@ -0,0 +1,15 @@
+#! /usr/bin/raku
+
+use Test;
+
+plan 3;
+
+is(oddletters('weekly'), False, 'example 1');
+is(oddletters('perl'), True, 'example 2');
+is(oddletters('challenge'), False, 'example 3');
+
+sub oddletters($a) {
+ my %c;
+ $a.comb('').map({%c{$_}++});
+ (%c.values.all % 2 == 1).Bool;
+}
diff --git a/challenge-332/roger-bell-west/ruby/ch-1.rb b/challenge-332/roger-bell-west/ruby/ch-1.rb
new file mode 100755
index 0000000000..3f4f401381
--- /dev/null
+++ b/challenge-332/roger-bell-west/ruby/ch-1.rb
@@ -0,0 +1,23 @@
+#! /usr/bin/ruby
+
+def binarydate(a)
+ a.split("-").map{|n| n.to_i.to_s(2)}.join("-")
+end
+
+require 'test/unit'
+
+class TestBinarydate < Test::Unit::TestCase
+
+ def test_ex1
+ assert_equal('11111101001-111-11010', binarydate('2025-07-26'))
+ end
+
+ def test_ex2
+ assert_equal('11111010000-10-10', binarydate('2000-02-02'))
+ end
+
+ def test_ex3
+ assert_equal('11111101000-1100-11111', binarydate('2024-12-31'))
+ end
+
+end
diff --git a/challenge-332/roger-bell-west/ruby/ch-2.rb b/challenge-332/roger-bell-west/ruby/ch-2.rb
new file mode 100755
index 0000000000..3b9bd0b3ec
--- /dev/null
+++ b/challenge-332/roger-bell-west/ruby/ch-2.rb
@@ -0,0 +1,33 @@
+#! /usr/bin/ruby
+
+def counterify(a)
+ cc = Hash.new
+ cc.default = 0
+ a.each do |x|
+ cc[x] += 1
+ end
+ return cc
+end
+
+def oddletters(a)
+ c = counterify(a.chars)
+ c.values.all? { |v| v % 2 == 1 }
+end
+
+require 'test/unit'
+
+class TestOddletters < Test::Unit::TestCase
+
+ def test_ex1
+ assert_equal(false, oddletters('weekly'))
+ end
+
+ def test_ex2
+ assert_equal(true, oddletters('perl'))
+ end
+
+ def test_ex3
+ assert_equal(false, oddletters('challenge'))
+ end
+
+end
diff --git a/challenge-332/roger-bell-west/rust/ch-1.rs b/challenge-332/roger-bell-west/rust/ch-1.rs
new file mode 100755
index 0000000000..94658f53b8
--- /dev/null
+++ b/challenge-332/roger-bell-west/rust/ch-1.rs
@@ -0,0 +1,24 @@
+#! /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!(binarydate("2025-07-26"), "11111101001-111-11010");
+}
+
+#[test]
+fn test_ex2() {
+ assert_eq!(binarydate("2000-02-02"), "11111010000-10-10");
+}
+
+#[test]
+fn test_ex3() {
+ assert_eq!(binarydate("2024-12-31"), "11111101000-1100-11111");
+}
+
+fn binarydate(a: &str) -> String {
+ a.split('-')
+ .map(|n| format!("{:0b}", n.parse::<u32>().unwrap()))
+ .collect::<Vec<_>>()
+ .join("-")
+}
diff --git a/challenge-332/roger-bell-west/rust/ch-2.rs b/challenge-332/roger-bell-west/rust/ch-2.rs
new file mode 100755
index 0000000000..f178dfb5c6
--- /dev/null
+++ b/challenge-332/roger-bell-west/rust/ch-2.rs
@@ -0,0 +1,21 @@
+use counter::Counter;
+
+#[test]
+fn test_ex1() {
+ assert_eq!(oddletters("weekly"), false);
+}
+
+#[test]
+fn test_ex2() {
+ assert_eq!(oddletters("perl"), true);
+}
+
+#[test]
+fn test_ex3() {
+ assert_eq!(oddletters("challenge"), false);
+}
+
+fn oddletters(a: &str) -> bool {
+ let c = a.chars().collect::<Counter<_>>();
+ c.values().all(|v| v % 2 == 1)
+}
diff --git a/challenge-332/roger-bell-west/scala/ch-1.scala b/challenge-332/roger-bell-west/scala/ch-1.scala
new file mode 100644
index 0000000000..840aa8a029
--- /dev/null
+++ b/challenge-332/roger-bell-west/scala/ch-1.scala
@@ -0,0 +1,27 @@
+
+object Binarydate {
+ def binarydate(a: String): String = {
+ a.split("-").map(n => n.toInt.toBinaryString).mkString("-")
+ }
+ def main(args: Array[String]) {
+ if (binarydate("2025-07-26") == "11111101001-111-11010") {
+ print("Pass")
+ } else {
+ print("Fail")
+ }
+ print(" ")
+ if (binarydate("2000-02-02") == "11111010000-10-10") {
+ print("Pass")
+ } else {
+ print("Fail")
+ }
+ print(" ")
+ if (binarydate("2024-12-31") == "11111101000-1100-11111") {
+ print("Pass")
+ } else {
+ print("Fail")
+ }
+ println("")
+
+ }
+}
diff --git a/challenge-332/roger-bell-west/scala/ch-2.scala b/challenge-332/roger-bell-west/scala/ch-2.scala
new file mode 100644
index 0000000000..7335ec8524
--- /dev/null
+++ b/challenge-332/roger-bell-west/scala/ch-2.scala
@@ -0,0 +1,38 @@
+import scala.collection.mutable
+
+object Oddletters {
+ def counterify(a: List[Char]): Map[Char, Int] = {
+ var cc = mutable.Map.empty[Char, Int].withDefaultValue(0)
+ for (x <- a) {
+ cc += (x -> (cc(x) + 1))
+ }
+ cc.toMap
+ }
+
+ def oddletters(a: String): Boolean = {
+ val c = counterify(a.toCharArray.toList);
+ c.values.forall(_ % 2 == 1)
+ }
+
+ def main(args: Array[String]) {
+ if (!oddletters("weekly")) {
+ print("Pass")
+ } else {
+ print("Fail")
+ }
+ print(" ")
+ if (oddletters("perl")) {
+ print("Pass")
+ } else {
+ print("Fail")
+ }
+ print(" ")
+ if (!oddletters("challenge")) {
+ print("Pass")
+ } else {
+ print("Fail")
+ }
+ println("")
+
+ }
+}
diff --git a/challenge-332/roger-bell-west/tests.json b/challenge-332/roger-bell-west/tests.json
new file mode 100644
index 0000000000..de49682a74
--- /dev/null
+++ b/challenge-332/roger-bell-west/tests.json
@@ -0,0 +1,32 @@
+{
+ "ch-1" : [
+ {
+ "function" : "binarydate",
+ "arguments" : "2025-07-26",
+ "result" : "11111101001-111-11010"
+ },
+ {
+ "arguments" : "2000-02-02",
+ "result" : "11111010000-10-10"
+ },
+ {
+ "arguments" : "2024-12-31",
+ "result" : "11111101000-1100-11111"
+ }
+ ],
+ "ch-2" : [
+ {
+ "function" : "oddletters",
+ "arguments" : "weekly",
+ "result" : false
+ },
+ {
+ "arguments" : "perl",
+ "result" : true
+ },
+ {
+ "arguments" : "challenge",
+ "result" : false
+ }
+ ]
+}
diff --git a/challenge-332/roger-bell-west/typst/ch-1.typ b/challenge-332/roger-bell-west/typst/ch-1.typ
new file mode 100644
index 0000000000..9b7b3a38f4
--- /dev/null
+++ b/challenge-332/roger-bell-west/typst/ch-1.typ
@@ -0,0 +1,39