diff options
25 files changed, 908 insertions, 0 deletions
diff --git a/challenge-319/roger-bell-west/crystal/ch-1.cr b/challenge-319/roger-bell-west/crystal/ch-1.cr new file mode 100755 index 0000000000..eb881d1366 --- /dev/null +++ b/challenge-319/roger-bell-west/crystal/ch-1.cr @@ -0,0 +1,32 @@ +#! /usr/bin/crystal + +def wordcount(a) + ct = 0 + a.each do |w| + ct += case w[0] + when 'a', 'e', 'i', 'o', 'u' + 1 + else + case w[-1] + when 'a', 'e', 'i', 'o', 'u' + 1 + else + 0 + end + end + end + ct +end + +require "spec" +describe "wordcount" do + it "test_ex1" do + wordcount(["unicode", "xml", "raku", "perl"]).should eq 2 + end + it "test_ex2" do + wordcount(["the", "weekly", "challenge"]).should eq 2 + end + it "test_ex3" do + wordcount(["perl", "python", "postgres"]).should eq 0 + end +end diff --git a/challenge-319/roger-bell-west/crystal/ch-2.cr b/challenge-319/roger-bell-west/crystal/ch-2.cr new file mode 100755 index 0000000000..3cc807753d --- /dev/null +++ b/challenge-319/roger-bell-west/crystal/ch-2.cr @@ -0,0 +1,25 @@ +#! /usr/bin/crystal + +def minimumcommon(a, b) + aa = a.to_set + bb = b.to_set + cc = a & b + if cc.size == 0 + -1 + else + cc.min + end +end + +require "spec" +describe "minimumcommon" do + it "test_ex1" do + minimumcommon([1, 2, 3, 4], [3, 4, 5, 6]).should eq 3 + end + it "test_ex2" do + minimumcommon([1, 2, 3], [2, 4]).should eq 2 + end + it "test_ex3" do + minimumcommon([1, 2, 3, 4], [5, 6, 7, 8]).should eq -1 + end +end diff --git a/challenge-319/roger-bell-west/javascript/ch-1.js b/challenge-319/roger-bell-west/javascript/ch-1.js new file mode 100755 index 0000000000..c6b5d71db0 --- /dev/null +++ b/challenge-319/roger-bell-west/javascript/ch-1.js @@ -0,0 +1,49 @@ +#! /usr/bin/node + +"use strict" + +function is_vowel(c) { + switch (c.toLowerCase()) { + case "a": + return true; + case "e": + return true; + case "i": + return true; + case "o": + return true; + case "u": + return true; + default: + return false; + } +} + +function wordcount(a) { + let ct = 0; + for (let w of a) { + if (is_vowel(w.slice(1)) || is_vowel(w.slice(-1))) { + ct++; + } + } + return ct; +} + +if (wordcount(['unicode', 'xml', 'raku', 'perl']) == 2) { + process.stdout.write("Pass"); +} else { + process.stdout.write("FAIL"); +} +process.stdout.write(" "); +if (wordcount(['the', 'weekly', 'challenge']) == 2) { + process.stdout.write("Pass"); +} else { + process.stdout.write("FAIL"); +} +process.stdout.write(" "); +if (wordcount(['perl', 'python', 'postgres']) == 0) { + process.stdout.write("Pass"); +} else { + process.stdout.write("FAIL"); +} +process.stdout.write("\n"); diff --git a/challenge-319/roger-bell-west/javascript/ch-2.js b/challenge-319/roger-bell-west/javascript/ch-2.js new file mode 100755 index 0000000000..e00a38647a --- /dev/null +++ b/challenge-319/roger-bell-west/javascript/ch-2.js @@ -0,0 +1,35 @@ +#! /usr/bin/node + +"use strict" + +function minimumcommon(a, b) { + const aa = new Set(a); + const bb = new Set(b); + const cc = new Set([...aa].filter(i => bb.has(i))); + if (cc.size == 0) { + return -1; + } else { + let o = [...cc]; + o.sort(); + return o[0]; + } +} + +if (minimumcommon([1, 2, 3, 4], [3, 4, 5, 6]) == 3) { + process.stdout.write("Pass"); +} else { + process.stdout.write("FAIL"); +} +process.stdout.write(" "); +if (minimumcommon([1, 2, 3], [2, 4]) == 2) { + process.stdout.write("Pass"); +} else { + process.stdout.write("FAIL"); +} +process.stdout.write(" "); +if (minimumcommon([1, 2, 3, 4], [5, 6, 7, 8]) == -1) { + process.stdout.write("Pass"); +} else { + process.stdout.write("FAIL"); +} +process.stdout.write("\n"); diff --git a/challenge-319/roger-bell-west/kotlin/ch-1.kt b/challenge-319/roger-bell-west/kotlin/ch-1.kt new file mode 100644 index 0000000000..ec32877322 --- /dev/null +++ b/challenge-319/roger-bell-west/kotlin/ch-1.kt @@ -0,0 +1,38 @@ +fun wordcount(a: List<String>): Int { + var ct = 0 + for (w in a) { + ct += when(w.first()) { + 'a', 'e', 'i', 'o', 'u' -> 1 + else -> { + when(w.last()) { + 'a', 'e', 'i', 'o', 'u' -> 1 + else -> 0 + } + } + } + } + return ct +} + +fun main() { + + if (wordcount(listOf("unicode", "xml", "raku", "perl")) == 2) { + print("Pass") + } else { + print("Fail") + } + print(" ") + if (wordcount(listOf("the", "weekly", "challenge")) == 2) { + print("Pass") + } else { + print("Fail") + } + print(" ") + if (wordcount(listOf("perl", "python", "postgres")) == 0) { + print("Pass") + } else { + print("Fail") + } + println("") + +} diff --git a/challenge-319/roger-bell-west/kotlin/ch-2.kt b/challenge-319/roger-bell-west/kotlin/ch-2.kt new file mode 100644 index 0000000000..a4612c7207 --- /dev/null +++ b/challenge-319/roger-bell-west/kotlin/ch-2.kt @@ -0,0 +1,33 @@ +fun minimumcommon(a: List<Int>, b: List<Int>): Int { + val aa = a.toSet() + val bb = b.toSet() + val cc = aa.intersect(bb).toList() + if (cc.size == 0) { + return -1 + } else { + return cc.minOrNull()!! + } +} + +fun main() { + + if (minimumcommon(listOf(1, 2, 3, 4), listOf(3, 4, 5, 6)) == 3) { + print("Pass") + } else { + print("Fail") + } + print(" ") + if (minimumcommon(listOf(1, 2, 3), listOf(2, 4)) == 2) { + print("Pass") + } else { + print("Fail") + } + print(" ") + if (minimumcommon(listOf(1, 2, 3, 4), listOf(5, 6, 7, 8)) == -1) { + print("Pass") + } else { + print("Fail") + } + println("") + +} diff --git a/challenge-319/roger-bell-west/lua/ch-1.lua b/challenge-319/roger-bell-west/lua/ch-1.lua new file mode 100755 index 0000000000..278ec95cbc --- /dev/null +++ b/challenge-319/roger-bell-west/lua/ch-1.lua @@ -0,0 +1,33 @@ +#! /usr/bin/lua + +function wordcount(a) + local ct = 0 + for _, w in ipairs(a) do + if string.match(w, "^[aeiou]") or string.match(w, "[aeiou]$") then + ct = ct + 1 + end + end + return ct +end + +if wordcount({"unicode", "xml", "raku", "perl"}) == 2 then + io.write("Pass") +else + io.write("FAIL") +end +io.write(" ") + +if wordcount({"the", "weekly", "challenge"}) == 2 then + io.write("Pass") +else + io.write("FAIL") +end +io.write(" ") + +if wordcount({"perl", "python", "postgres"}) == 0 then + io.write("Pass") +else + io.write("FAIL") +end +print("") + diff --git a/challenge-319/roger-bell-west/lua/ch-2.lua b/challenge-319/roger-bell-west/lua/ch-2.lua new file mode 100755 index 0000000000..7473b77343 --- /dev/null +++ b/challenge-319/roger-bell-west/lua/ch-2.lua @@ -0,0 +1,46 @@ +#! /usr/bin/lua + +function listtoset(a) + local s = {} + for _, x in ipairs(a) do + s[x] = true + end + return s +end + +function minimumcommon(a, b) + local aa = listtoset(a) + local cc = {} + for _, bx in ipairs(b) do + if aa[bx] ~= nil then + table.insert(cc, bx) + end + end + if #cc == 0 then + return -1 + else + return math.min(table.unpack(cc)) + end +end + +if minimumcommon({1, 2, 3, 4}, {3, 4, 5, 6}) == 3 then + io.write("Pass") +else + io.write("FAIL") +end +io.write(" ") + +if minimumcommon({1, 2, 3}, {2, 4}) == 2 then + io.write("Pass") +else + io.write("FAIL") +end +io.write(" ") + +if minimumcommon({1, 2, 3, 4}, {5, 6, 7, 8}) == -1 then + io.write("Pass") +else + io.write("FAIL") +end +print("") + diff --git a/challenge-319/roger-bell-west/perl/ch-1.pl b/challenge-319/roger-bell-west/perl/ch-1.pl new file mode 100755 index 0000000000..3cf3f07777 --- /dev/null +++ b/challenge-319/roger-bell-west/perl/ch-1.pl @@ -0,0 +1,21 @@ +#! /usr/bin/perl + +use strict; +use warnings; +use experimental 'signatures'; + +use Test::More tests => 3; + +is(wordcount(['unicode', 'xml', 'raku', 'perl']), 2, 'example 1'); +is(wordcount(['the', 'weekly', 'challenge']), 2, 'example 2'); +is(wordcount(['perl', 'python', 'postgres']), 0, 'example 3'); + +sub wordcount($a) { + my $ct = 0; + foreach my $w (@{$a}) { + if ($w =~ /^[aeiou]/ || $w =~ /[aeiou]$/) { + $ct++; + } + } + $ct; +} diff --git a/challenge-319/roger-bell-west/perl/ch-2.pl b/challenge-319/roger-bell-west/perl/ch-2.pl new file mode 100755 index 0000000000..8de8c6aaea --- /dev/null +++ b/challenge-319/roger-bell-west/perl/ch-2.pl @@ -0,0 +1,24 @@ +#! /usr/bin/perl + +use strict; +use warnings; +use experimental 'signatures'; + +use Test::More tests => 3; + +is(minimumcommon([1, 2, 3, 4], [3, 4, 5, 6]), 3, 'example 1'); +is(minimumcommon([1, 2, 3], [2, 4]), 2, 'example 2'); +is(minimumcommon([1, 2, 3, 4], [5, 6, 7, 8]), -1, 'example 3'); + +use List::Util qw(min); + +sub minimumcommon($a, $b) { + my %aa = map {$_ => 1} @{$a}; + my %bb = map {$_ => 1} @{$b}; + my %cc = map {$_ => 1} grep {exists $bb{$_}} keys %aa; + if (scalar keys %cc > 0) { + min(keys %cc); + } else { + -1; + } +} diff --git a/challenge-319/roger-bell-west/postscript/ch-1.ps b/challenge-319/roger-bell-west/postscript/ch-1.ps new file mode 100644 index 0000000000..3fd6b4cfa0 --- /dev/null +++ b/challenge-319/roger-bell-west/postscript/ch-1.ps @@ -0,0 +1,75 @@ +%!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 + +/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 + +/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.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 + +/wordcount { + 0 dict begin + [ exch + { + dup + 0 1 getinterval (aeiou) exch search { + pop pop pop pop 1 + } { + pop + dup length 1 sub 1 getinterval (aeiou) exch search { + pop pop pop 1 + } { + pop 0 + } ifelse + } ifelse + } forall + ] { add } reduce + end +} bind def + +(wordcount) test.start +[(unicode) (xml) (raku) (perl)] wordcount 2 eq test +[(the) (weekly) (challenge)] wordcount 2 eq test +[(perl) (python) (postgres)] wordcount 0 eq test +test.end diff --git a/challenge-319/roger-bell-west/postscript/ch-2.ps b/challenge-319/roger-bell-west/postscript/ch-2.ps new file mode 100644 index 0000000000..629a576fd3 --- /dev/null +++ b/challenge-319/roger-bell-west/postscript/ch-2.ps @@ -0,0 +1,102 @@ +%!PS + +% begin included library code +% see https://codeberg.org/Firedrake/postscript-libraries/ +/toset { % array -> dict of (value, true) + << exch + { + true + } 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 + +/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 + +/listmin { + { min } reduce +} bind def + +/set.intersection { + 4 dict begin + /s 0 dict def + /b exch def + /a exch def + a keys { + /k exch def + b k known { + s k true put + } if + } forall + s + end +} bind def + +/test.start { + print (:) print + /test.pass 0 def + /test.count 0 def +} bind def + +/keys { % dict -> array of dict keys + [ exch + { + pop + } forall + ] +} bind def + + + +% end included library code + +/minimumcommon { + toset exch + toset + set.intersection + dup length 0 eq { + -1 + } { + keys listmin + } ifelse +} bind def + +(minimumcommon) test.start +[1 2 3 4] [3 4 5 6] minimumcommon 3 eq test +[1 2 3] [2 4] minimumcommon 2 eq test +[1 2 3 4] [5 6 7 8] minimumcommon -1 eq test +test.end diff --git a/challenge-319/roger-bell-west/python/ch-1.py b/challenge-319/roger-bell-west/python/ch-1.py new file mode 100755 index 0000000000..35a590d8e0 --- /dev/null +++ b/challenge-319/roger-bell-west/python/ch-1.py @@ -0,0 +1,28 @@ +#! /usr/bin/python3 + +def wordcount(a): + ct = 0 + for w in a: + match w[0]: + case 'a' | 'e' | 'i' | 'o' | 'u': + ct += 1 + case _: + match w[-1]: + case 'a' | 'e' | 'i' | 'o' | 'u': + ct += 1 + return ct + +import unittest + +class TestWordcount(unittest.TestCase): + + def test_ex1(self): + self.assertEqual(wordcount(["unicode", "xml", "raku", "perl"]), 2, 'example 1') + + def test_ex2(self): + self.assertEqual(wordcount(["the", "weekly", "challenge"]), 2, 'example 2') + + def test_ex3(self): + self.assertEqual(wordcount(["perl", "python", "postgres"]), 0, 'example 3') + +unittest.main() diff --git a/challenge-319/roger-bell-west/python/ch-2.py b/challenge-319/roger-bell-west/python/ch-2.py new file mode 100755 index 0000000000..d302b5cff6 --- /dev/null +++ b/challenge-319/roger-bell-west/python/ch-2.py @@ -0,0 +1,25 @@ +#! /usr/bin/python3 + +def minimumcommon(a, b): + aa = set(a) + bb = set(b) + cc = aa.intersection(bb) + if len(cc) == 0: + return -1 + else: + return min(cc) + +import unittest + +class TestMinimumcommon(unittest.TestCase): + + def test_ex1(self): + self.assertEqual(minimumcommon([1, 2, 3, 4], [3, 4, 5, 6]), 3, 'example 1') + + def test_ex2(self): + self.assertEqual(minimumcommon([1, 2, 3], [2, 4]), 2, 'example 2') + + def test_ex3(self): + self.assertEqual(minimumcommon([1, 2, 3, 4], [5, 6, 7, 8]), -1, 'example 3') + +unittest.main() diff --git a/challenge-319/roger-bell-west/raku/ch-1.p6 b/challenge-319/roger-bell-west/raku/ch-1.p6 new file mode 100755 index 0000000000..029c678bc7 --- /dev/null +++ b/challenge-319/roger-bell-west/raku/ch-1.p6 @@ -0,0 +1,19 @@ +#! /usr/bin/raku + +use Test; + +plan 3; + +is(wordcount(['unicode', 'xml', 'raku', 'perl']), 2, 'example 1'); +is(wordcount(['the', 'weekly', 'challenge']), 2, 'example 2'); +is(wordcount(['perl', 'python', 'postgres']), 0, 'example 3'); + +sub wordcount(@a) { + my $ct = 0; + for @a -> $w { + if ($w ~~ /^<[aeiou]>/ || $w ~~ /<[aeiou]>$/) { + $ct++; + } + } + $ct; +} diff --git a/challenge-319/roger-bell-west/raku/ch-2.p6 b/challenge-319/roger-bell-west/raku/ch-2.p6 new file mode 100755 index 0000000000..0bbf53cb13 --- /dev/null +++ b/challenge-319/roger-bell-west/raku/ch-2.p6 @@ -0,0 +1,20 @@ +#! /usr/bin/raku + +use Test; + +plan 3; + +is(minimumcommon([1, 2, 3, 4], [3, 4, 5, 6]), 3, 'example 1'); +is(minimumcommon([1, 2, 3], [2, 4]), 2, 'example 2'); +is(minimumcommon([1, 2, 3, 4], [5, 6, 7, 8]), -1, 'example 3'); + +sub minimumcommon(@a, @b) { + my %aa = Set.new(@a); + my %bb = Set.new(@b); + my %cc = %aa (&) %bb; + if (%cc.elems > 0) { + %cc.keys.min; + } else { + -1; + } +} diff --git a/challenge-319/roger-bell-west/ruby/ch-1.rb b/challenge-319/roger-bell-west/ruby/ch-1.rb new file mode 100755 index 0000000000..1d95efc2c8 --- /dev/null +++ b/challenge-319/roger-bell-west/ruby/ch-1.rb @@ -0,0 +1,37 @@ +#! /usr/bin/ruby + +def wordcount(a) + ct = 0 + a.each do |w| + ct += case w[0] + when 'a', 'e', 'i', 'o', 'u' + 1 + else + case w[-1] + when 'a', 'e', 'i', 'o', 'u' + 1 + else + 0 + end + end + end + ct +end + +require 'test/unit' + +class TestWordcount < Test::Unit::TestCase + + def test_ex1 + assert_equal(2, wordcount(['unicode', 'xml', 'raku', 'perl'])) + end + + def test_ex2 + assert_equal(2, wordcount(['the', 'weekly', 'challenge'])) + end + + def test_ex3 + assert_equal(0, wordcount(['perl', 'python', 'postgres'])) + end + +end diff --git a/challenge-319/roger-bell-west/ruby/ch-2.rb b/challenge-319/roger-bell-west/ruby/ch-2.rb new file mode 100755 index 0000000000..9203f98365 --- /dev/null +++ b/challenge-319/roger-bell-west/ruby/ch-2.rb @@ -0,0 +1,32 @@ +#! /usr/bin/ruby + +require 'set' + +def minimumcommon(a, b) + aa = a.to_set + bb = b.to_set + cc = a & b + if cc.size == 0 + -1 + else + cc.min + end +end + +require 'test/unit' + +class TestMinimumcommon < Test::Unit::TestCase + + def test_ex1 + assert_equal(3, minimumcommon([1, 2, 3, 4], [3, 4, 5, 6])) + end + + def test_ex2 + assert_equal(2, minimumcommon([1, 2, 3], [2, 4])) + end + + def test_ex3 + assert_equal(-1, minimumcommon([1, 2, 3, 4], [5, 6, 7, 8])) + end + +end diff --git a/challenge-319/roger-bell-west/rust/ch-1.rs b/challenge-319/roger-bell-west/rust/ch-1.rs new file mode 100755 index 0000000000..7737602483 --- /dev/null +++ b/challenge-319/roger-bell-west/rust/ch-1.rs @@ -0,0 +1,32 @@ +#! /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!(wordcount(vec!["unicode", "xml", "raku", "perl"]), 2); +} + +#[test] +fn test_ex2() { + assert_eq!(wordcount(vec!["the", "weekly", "challenge"]), 2); +} + +#[test] +fn test_ex3() { + assert_eq!(wordcount(vec!["perl", "python", "postgres"]), 0); +} + +fn wordcount(a: Vec<&str>) -> usize { + let mut ct = 0; + for w in a { + let mut c = w.chars(); + ct += match c.nth(0).unwrap() { + 'a' | 'e' | 'i' | 'o' | 'u' => 1, + _ => match c.last().unwrap() { + 'a' | 'e' | 'i' | 'o' | 'u' => 1, + _ => 0, + }, + }; + } + ct +} diff --git a/challenge-319/roger-bell-west/rust/ch-2.rs b/challenge-319/roger-bell-west/rust/ch-2.rs new file mode 100755 index 0000000000..093a54f82d --- /dev/null +++ b/challenge-319/roger-bell-west/rust/ch-2.rs @@ -0,0 +1,30 @@ +#! /bin/sh +//usr/bin/env rustc --test $0 -o ${0}x && ./${0}x --nocapture; rm -f ${0}x ; exit + +use std::collections::HashSet; + +#[test] +fn test_ex1() { + assert_eq!(minimumcommon(vec![1, 2, 3, 4], vec![3, 4, 5, 6]), 3); +} + +#[test] +fn test_ex2() { + assert_eq!(minimumcommon(vec![1, 2, 3], vec![2, 4]), 2); +} + +#[test] +fn test_ex3() { + assert_eq!(minimumcommon(vec![1, 2, 3, 4], vec![5, 6, 7, 8]), -1); +} + +fn minimumcommon(a: Vec<usize>, b: Vec<usize>) -> isize { + let aa = a.into_iter().collect::<HashSet<usize>>(); + let bb = b.into_iter().collect::<HashSet<usize>>(); + let cc = aa.intersection(&bb); + if cc.clone().count() > 0 { + *cc.min().unwrap() as isize + } else { + -1 + } +} diff --git a/challenge-319/roger-bell-west/scala/ch-1.scala b/challenge-319/roger-bell-west/scala/ch-1.scala new file mode 100644 index 0000000000..f8d8978e27 --- /dev/null +++ b/challenge-319/roger-bell-west/scala/ch-1.scala @@ -0,0 +1,39 @@ + +object Wordcount { + def wordcount(a: List[String]): Int = { + var ct = 0 + for (w <- a) { + val d = w.charAt(0) match { + case 'a' | 'e' | 'i' | 'o' | 'u' => 1 + case _ => { + w.charAt(w.length - 1) match { + case 'a' | 'e' | 'i' | 'o' | 'u' => 1 + case _ => 0 + } + } + } + ct += d + } + ct + } + def main(args: Array[String]) { + if (wordcount(List("unicode", "xml", "raku", "perl")) == 2) { + print("Pass") + } else { + print("Fail") + } + print(" ") + if (wordcount(List("the", "weekly", "challenge")) == 2) { + print("Pass") + } else { + print("Fail") + } + print(" ") + if (wordcount(List("perl", "python", "postgres")) == 0) { + print("Pass") + } else { + print("Fail") + } + println("") + } +} diff --git a/challenge-319/roger-bell-west/scala/ch-2.scala b/challenge-319/roger-bell-west/scala/ch-2.scala new file mode 100644 index 0000000000..e0c8ec7849 --- /dev/null +++ b/challenge-319/roger-bell-west/scala/ch-2.scala @@ -0,0 +1,34 @@ + +object Minimumcommon { + def minimumcommon(a: List[Int], b: List[Int]): Int = { + val aa = a.toSet + val bb = b.toSet + val cc = aa.intersect(bb).toList + if (cc.size == 0) { + -1 + } else { + cc.min + } + } + def main(args: Array[String]) { + if (minimumcommon(List(1, 2, 3, 4), List(3, 4, 5, 6)) == 3) { + print("Pass") + } else { + print("Fail") + } + print(" ") + if (minimumcommon(List(1, 2, 3), List(2, 4)) == 2) { + print("Pass") + } else { + print("Fail") + } + print(" ") + if (minimumcommon(List(1, 2, 3, 4), List(5, 6, 7, 8)) == -1) { + print("Pass") + } else { + print("Fail") + } + println("") + + } +} diff --git a/challenge-319/roger-bell-west/tests.json b/challenge-319/roger-bell-west/tests.json new file mode 100644 index 0000000000..0f81a60e29 --- /dev/null +++ b/challenge-319/roger-bell-west/tests.json @@ -0,0 +1,44 @@ +{ + "ch-1" : [ + { + "function" : "wordcount", + "arguments" : ["unicode", "xml", "raku", "perl"], + "result" : 2 + }, + { + "arguments" : ["the", "weekly", "challenge"], + "result" : 2 + }, + { + "arguments" : ["perl", "python", "postgres"], + "result" : 0 + } + ], + "ch-2" : [ + { + "function" : "minimumcommon", + "multiarg" : "true", + "arguments" : [ + [ 1, 2, 3, 4 ], + [ 3, 4, 5, 6 ] + ], + "result" : 3 + }, + { + "multiarg" : "true", + "arguments" : [ + [ 1, 2, 3 ], + [ 2, 4 ] + ], + "result" : 2 + }, + { + "multiarg" : "true", + "arguments" : [ + [ 1, 2, 3, 4 ], + [ 5, 6, 7, 8 ] + ], + "result" : -1 + } + ] +} diff --git a/challenge-319/roger-bell-west/typst/ch-1.typ b/challenge-319/roger-bell-west/typst/ch-1.typ new file mode 100644 index 0000000000..500b0ed9d8 --- /dev/null +++ b/challenge-319/roger-bell-west/typst/ch-1.typ @@ -0,0 +1,23 @@ +#let testresult(pass) = { + if pass { + text(fill: green, "Pass") + } else { + text(fill: red, "Fail") + } +} + +#let wordcount(a) = { + let ct = 0 + for w in a { + if w.starts-with(regex("[aeiou]")) or w.ends-with(regex("[aeiou]")) { + ct += 1 + } + } + ct +} + +Test 1: #testresult(wordcount(("unicode", "xml", "raku", "perl")) == 2) + +Test 2: #testresult(wordcount(("the", "weekly", "challenge")) == 2) + +Test 3: #testresult(wordcount(("perl", "python", "postgres")) == 0) diff --git a/challenge-319/roger-bell-west/typst/ch-2.typ b/challenge-319/roger-bell-west/typst/ch-2.typ new file mode 100644 index 0000000000..34cff1f576 --- /dev/null +++ b/challenge-319/roger-bell-west/typst/ch-2.typ @@ -0,0 +1,32 @@ +#let arr2set(a) = { + a.map(x => (str(x), true)).to-dict() +} + +#let minimumcommon(a, b) = { + let aa = arr2set(a) + let bb = arr2set(b) + let cc = aa.keys().filter(x => x in bb).map(x => int(x)) + if cc.len() == 0 { + -1 + } else { + calc.min(.. cc) + } +} + |
