aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xchallenge-345/roger-bell-west/crystal/ch-1.cr30
-rwxr-xr-xchallenge-345/roger-bell-west/crystal/ch-2.cr40
-rw-r--r--challenge-345/roger-bell-west/postscript/ch-1.ps148
-rw-r--r--challenge-345/roger-bell-west/postscript/ch-2.ps132
-rwxr-xr-xchallenge-345/roger-bell-west/raku/ch-1.p622
-rwxr-xr-xchallenge-345/roger-bell-west/raku/ch-2.p631
-rwxr-xr-xchallenge-345/roger-bell-west/ruby/ch-1.rb37
-rwxr-xr-xchallenge-345/roger-bell-west/ruby/ch-2.rb47
-rwxr-xr-xchallenge-345/roger-bell-west/rust/ch-1.rs37
-rwxr-xr-xchallenge-345/roger-bell-west/rust/ch-2.rs49
-rw-r--r--challenge-345/roger-bell-west/scala/ch-1.scala47
-rw-r--r--challenge-345/roger-bell-west/scala/ch-2.scala56
-rw-r--r--challenge-345/roger-bell-west/tests.json48
-rw-r--r--challenge-345/roger-bell-west/typst/ch-1.typ33
-rw-r--r--challenge-345/roger-bell-west/typst/ch-2.typ43
15 files changed, 800 insertions, 0 deletions
diff --git a/challenge-345/roger-bell-west/crystal/ch-1.cr b/challenge-345/roger-bell-west/crystal/ch-1.cr
new file mode 100755
index 0000000000..946de429e2
--- /dev/null
+++ b/challenge-345/roger-bell-west/crystal/ch-1.cr
@@ -0,0 +1,30 @@
+#! /usr/bin/crystal
+
+def peakpositions(a)
+ out = Array(Int32).new
+ a.each_with_index do |x, i|
+ if (i == 0 || x > a[i - 1]) && (i == a.size() - 1 || x > a[i + 1])
+ out.push(i)
+ end
+ end
+ out
+end
+
+require "spec"
+describe "peakpositions" do
+ it "test_ex1" do
+ peakpositions([1, 3, 2]).should eq [1]
+ end
+ it "test_ex2" do
+ peakpositions([2, 4, 6, 5, 3]).should eq [2]
+ end
+ it "test_ex3" do
+ peakpositions([1, 2, 3, 2, 4, 1]).should eq [2, 4]
+ end
+ it "test_ex4" do
+ peakpositions([5, 3, 1]).should eq [0]
+ end
+ it "test_ex5" do
+ peakpositions([1, 5, 1, 5, 1, 5, 1]).should eq [1, 3, 5]
+ end
+end
diff --git a/challenge-345/roger-bell-west/crystal/ch-2.cr b/challenge-345/roger-bell-west/crystal/ch-2.cr
new file mode 100755
index 0000000000..fc486023c6
--- /dev/null
+++ b/challenge-345/roger-bell-west/crystal/ch-2.cr
@@ -0,0 +1,40 @@
+#! /usr/bin/crystal
+
+def lastvisitor(a)
+ seen = Array(Int32).new
+ ans = Array(Int32).new
+ minusones = 0
+ a.each do |n|
+ if n == -1
+ minusones += 1
+ if minusones <= seen.size
+ ans.push(seen[minusones - 1])
+ else
+ ans.push(-1)
+ end
+ else
+ seen.unshift(n)
+ minusones = 0
+ end
+ end
+ ans
+end
+
+require "spec"
+describe "lastvisitor" do
+ it "test_ex1" do
+ lastvisitor([5, -1, -1]).should eq [5, -1]
+ end
+ it "test_ex2" do
+ lastvisitor([3, 7, -1, -1, -1]).should eq [7, 3, -1]
+ end
+ it "test_ex3" do
+ lastvisitor([2, -1, 4, -1, -1]).should eq [2, 4, 2]
+ end
+ it "test_ex4" do
+ lastvisitor([10, 20, -1, 30, -1, -1]).should eq [20, 30, 20]
+ end
+ it "test_ex5" do
+ lastvisitor([-1, -1, 5, -1]).should eq [-1, -1, 5]
+ end
+end
diff --git a/challenge-345/roger-bell-west/postscript/ch-1.ps b/challenge-345/roger-bell-west/postscript/ch-1.ps
new file mode 100644
index 0000000000..c5362640b5
--- /dev/null
+++ b/challenge-345/roger-bell-west/postscript/ch-1.ps
@@ -0,0 +1,148 @@
+%!PS
+
+% begin included library code
+% see https://codeberg.org/Firedrake/postscript-libraries/
+/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
+
+/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
+
+/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
+
+/enumerate.array {
+ 1 dict begin
+ /a exch def
+ [
+ 0 1 a length 1 sub {
+ [ exch dup a exch get ]
+ } for
+ ]
+ end
+} bind def
+
+
+% end included library code
+
+/peakpositions {
+ 0 dict begin
+ /a exch def
+ [
+ a enumerate.array {
+ aload pop
+ /x exch def
+ /i exch def
+ /l false def
+ i 0 eq {
+ /l true def
+ } if
+ l not {
+ x a i 1 sub get gt {
+ /l true def
+ } if
+ } if
+ /r false def
+ i a length 1 sub eq {
+ /r true def
+ } if
+ r not {
+ x a i 1 add get gt {
+ /r true def
+ } if
+ } if
+ l r and {
+ i
+ } if
+ } forall
+ ]
+ end
+} bind def
+
+(peakpositions) test.start
+[1 3 2] peakpositions [1] deepeq test
+[2 4 6 5 3] peakpositions [2] deepeq test
+[1 2 3 2 4 1] peakpositions [2 4] deepeq test
+[5 3 1] peakpositions [0] deepeq test
+[1 5 1 5 1 5 1] peakpositions [1 3 5] deepeq test
+test.end
diff --git a/challenge-345/roger-bell-west/postscript/ch-2.ps b/challenge-345/roger-bell-west/postscript/ch-2.ps
new file mode 100644
index 0000000000..e6d7cfd020
--- /dev/null
+++ b/challenge-345/roger-bell-west/postscript/ch-2.ps
@@ -0,0 +1,132 @@
+%!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
+
+/apush.left { % [b c] a -> [a b c]
+ exch % a [b c]
+ [ 3 1 roll aload pop ]
+} 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
+
+/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
+
+
+% end included library code
+
+/lastvisitor {
+ 0 dict begin
+ /a exch def
+ [
+ /seen 0 array def
+ /minusones 0 def
+ a {
+ /n exch def
+ n -1 eq {
+ /minusones minusones 1 add def
+ minusones seen length le {
+ seen minusones 1 sub get
+ } {
+ -1
+ } ifelse
+ } {
+ /seen seen n apush.left def
+ /minusones 0 def
+ } ifelse
+ } forall
+ ]
+ end
+} bind def
+
+(lastvisitor) test.start
+[5 -1 -1] lastvisitor [5 -1] deepeq test
+[3 7 -1 -1 -1] lastvisitor [7 3 -1] deepeq test
+[2 -1 4 -1 -1] lastvisitor [2 4 2] deepeq test
+[10 20 -1 30 -1 -1] lastvisitor [20 30 20] deepeq test
+[-1 -1 5 -1] lastvisitor [-1 -1 5] deepeq test
+test.end
diff --git a/challenge-345/roger-bell-west/raku/ch-1.p6 b/challenge-345/roger-bell-west/raku/ch-1.p6
new file mode 100755
index 0000000000..621646317a
--- /dev/null
+++ b/challenge-345/roger-bell-west/raku/ch-1.p6
@@ -0,0 +1,22 @@
+#! /usr/bin/raku
+
+use Test;
+
+plan 5;
+
+is-deeply(peakpositions([1, 3, 2]), [1], 'example 1');
+is-deeply(peakpositions([2, 4, 6, 5, 3]), [2], 'example 2');
+is-deeply(peakpositions([1, 2, 3, 2, 4, 1]), [2, 4], 'example 3');
+is-deeply(peakpositions([5, 3, 1]), [0], 'example 4');
+is-deeply(peakpositions([1, 5, 1, 5, 1, 5, 1]), [1, 3, 5], 'example 5');
+
+sub peakpositions(@a) {
+ my @out;
+ for @a.kv -> $i, $x {
+ if (($i == 0 || $x > @a[$i - 1]) &&
+ ($i == @a.end || $x > @a[$i + 1])) {
+ @out.push($i);
+ }
+ }
+ @out;
+}
diff --git a/challenge-345/roger-bell-west/raku/ch-2.p6 b/challenge-345/roger-bell-west/raku/ch-2.p6
new file mode 100755
index 0000000000..89be3fcad7
--- /dev/null
+++ b/challenge-345/roger-bell-west/raku/ch-2.p6
@@ -0,0 +1,31 @@
+#! /usr/bin/raku
+
+use Test;
+
+plan 5;
+
+is-deeply(lastvisitor([5, -1, -1]), [5, -1], 'example 1');
+is-deeply(lastvisitor([3, 7, -1, -1, -1]), [7, 3, -1], 'example 2');
+is-deeply(lastvisitor([2, -1, 4, -1, -1]), [2, 4, 2], 'example 3');
+is-deeply(lastvisitor([10, 20, -1, 30, -1, -1]), [20, 30, 20], 'example 4');
+is-deeply(lastvisitor([-1, -1, 5, -1]), [-1, -1, 5], 'example 5');
+
+sub lastvisitor(@a) {
+ my @seen;
+ my @ans;
+ my $minusones = 0;
+ for @a -> $n {
+ if ($n == -1) {
+ $minusones++;
+ if ($minusones <= @seen.elems) {
+ @ans.push(@seen[$minusones - 1]);
+ } else {
+ @ans.push(-1);
+ }
+ } else {
+ @seen.unshift($n);
+ $minusones = 0;
+ }
+ }
+ @ans;
+}
diff --git a/challenge-345/roger-bell-west/ruby/ch-1.rb b/challenge-345/roger-bell-west/ruby/ch-1.rb
new file mode 100755
index 0000000000..9dc1f1d8fd
--- /dev/null
+++ b/challenge-345/roger-bell-west/ruby/ch-1.rb
@@ -0,0 +1,37 @@
+#! /usr/bin/ruby
+
+def peakpositions(a)
+ out = []
+ a.each_with_index do |x, i|
+ if (i == 0 || x > a[i - 1]) && (i == a.size() - 1 || x > a[i + 1])
+ out.push(i)
+ end
+ end
+ out
+end
+
+require 'test/unit'
+
+class TestPeakpositions < Test::Unit::TestCase
+
+ def test_ex1
+ assert_equal([1], peakpositions([1, 3, 2]))
+ end
+
+ def test_ex2
+ assert_equal([2], peakpositions([2, 4, 6, 5, 3]))
+ end
+
+ def test_ex3
+ assert_equal([2, 4], peakpositions([1, 2, 3, 2, 4, 1]))
+ end
+
+ def test_ex4
+ assert_equal([0], peakpositions([5, 3, 1]))
+ end
+
+ def test_ex5
+ assert_equal([1, 3, 5], peakpositions([1, 5, 1, 5, 1, 5, 1]))
+ end
+
+end
diff --git a/challenge-345/roger-bell-west/ruby/ch-2.rb b/challenge-345/roger-bell-west/ruby/ch-2.rb
new file mode 100755
index 0000000000..bb1c9b5e77
--- /dev/null
+++ b/challenge-345/roger-bell-west/ruby/ch-2.rb
@@ -0,0 +1,47 @@
+#! /usr/bin/ruby
+
+def lastvisitor(a)
+ seen = []
+ ans = []
+ minusones = 0
+ a.each do |n|
+ if n == -1
+ minusones += 1
+ if minusones <= seen.size
+ ans.push(seen[minusones - 1])
+ else
+ ans.push(-1)
+ end
+ else
+ seen.unshift(n)
+ minusones = 0
+ end
+ end
+ ans
+end
+
+require 'test/unit'
+
+class TestLastvisitor < Test::Unit::TestCase
+
+ def test_ex1
+ assert_equal([5, -1], lastvisitor([5, -1, -1]))
+ end
+
+ def test_ex2
+ assert_equal([7, 3, -1], lastvisitor([3, 7, -1, -1, -1]))
+ end
+
+ def test_ex3
+ assert_equal([2, 4, 2], lastvisitor([2, -1, 4, -1, -1]))
+ end
+
+ def test_ex4
+ assert_equal([20, 30, 20], lastvisitor([10, 20, -1, 30, -1, -1]))
+ end
+
+ def test_ex5
+ assert_equal([-1, -1, 5], lastvisitor([-1, -1, 5, -1]))
+ end
+
+end
diff --git a/challenge-345/roger-bell-west/rust/ch-1.rs b/challenge-345/roger-bell-west/rust/ch-1.rs
new file mode 100755
index 0000000000..d2cb6c31bd
--- /dev/null
+++ b/challenge-345/roger-bell-west/rust/ch-1.rs
@@ -0,0 +1,37 @@
+#! /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!(peakpositions(vec![1, 3, 2]), vec![1]);
+}
+
+#[test]
+fn test_ex2() {
+ assert_eq!(peakpositions(vec![2, 4, 6, 5, 3]), vec![2]);
+}
+
+#[test]
+fn test_ex3() {
+ assert_eq!(peakpositions(vec![1, 2, 3, 2, 4, 1]), vec![2, 4]);
+}
+
+#[test]
+fn test_ex4() {
+ assert_eq!(peakpositions(vec![5, 3, 1]), vec![0]);
+}
+
+#[test]
+fn test_ex5() {
+ assert_eq!(peakpositions(vec![1, 5, 1, 5, 1, 5, 1]), vec![1, 3, 5]);
+}
+
+fn peakpositions(a: Vec<i32>) -> Vec<usize> {
+ let mut out = Vec::new();
+ for (i, x) in a.iter().enumerate() {
+ if (i == 0 || *x > a[i - 1]) && (i == a.len() - 1 || *x > a[i + 1]) {
+ out.push(i);
+ }
+ }
+ out
+}
diff --git a/challenge-345/roger-bell-west/rust/ch-2.rs b/challenge-345/roger-bell-west/rust/ch-2.rs
new file mode 100755
index 0000000000..af160a6f48
--- /dev/null
+++ b/challenge-345/roger-bell-west/rust/ch-2.rs
@@ -0,0 +1,49 @@
+#! /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!(lastvisitor(vec![5, -1, -1]), vec![5, -1]);
+}
+
+#[test]
+fn test_ex2() {
+ assert_eq!(lastvisitor(vec![3, 7, -1, -1, -1]), vec![7, 3, -1]);
+}
+
+#[test]
+fn test_ex3() {
+ assert_eq!(lastvisitor(vec![2, -1, 4, -1, -1]), vec![2, 4, 2]);
+}
+
+#[test]
+fn test_ex4() {
+ assert_eq!(lastvisitor(vec![10, 20, -1, 30, -1, -1]), vec![20, 30, 20]);
+}
+
+#[test]
+fn test_ex5() {
+ assert_eq!(lastvisitor(vec![-1, -1, 5, -1]), vec![-1, -1, 5]);
+}
+
+use std::collections::VecDeque;
+
+fn lastvisitor(a: Vec<i32>) -> Vec<i32> {
+ let mut seen = VecDeque::new();
+ let mut ans = Vec::new();
+ let mut minusones = 0;
+ for n in a {
+ if n == -1 {
+ minusones += 1;
+ if minusones <= seen.len() {
+ ans.push(seen[minusones - 1]);
+ } else {
+ ans.push(-1);
+ }
+ } else {
+ seen.push_front(n);
+ minusones = 0;
+ }
+ }
+ ans
+}
diff --git a/challenge-345/roger-bell-west/scala/ch-1.scala b/challenge-345/roger-bell-west/scala/ch-1.scala
new file mode 100644
index 0000000000..f7f52d0233
--- /dev/null
+++ b/challenge-345/roger-bell-west/scala/ch-1.scala
@@ -0,0 +1,47 @@
+import scala.collection.mutable.ListBuffer
+
+object Peakpositions {
+ def peakpositions(a: List[Int]): List[Int] = {
+ var out = new ListBuffer[Int]
+ for ((x, i) <- a.zipWithIndex) {
+ if ((i == 0 || x > a(i - 1)) &&
+ (i == a.size - 1 || x > a(i + 1))) {
+ out += i
+ }
+ }
+ out.toList
+ }
+ def main(args: Array[String]) {
+ if (peakpositions(List(1, 3, 2)) == List(1)) {
+ print("Pass")
+ } else {
+ print("Fail")
+ }
+ print(" ")
+ if (peakpositions(List(2, 4, 6, 5, 3)) == List(2)) {
+ print("Pass")
+ } else {
+ print("Fail")
+ }
+ print(" ")
+ if (peakpositions(List(1, 2, 3, 2, 4, 1)) == List(2, 4)) {
+ print("Pass")
+ } else {
+ print("Fail")
+ }
+ print(" ")
+ if (peakpositions(List(5, 3, 1)) == List(0)) {
+ print("Pass")
+ } else {
+ print("Fail")
+ }
+ print(" ")
+ if (peakpositions(List(1, 5, 1, 5, 1, 5, 1)) == List(1, 3, 5)) {
+ print("Pass")
+ } else {
+ print("Fail")
+ }
+ println("")
+
+ }
+}
diff --git a/challenge-345/roger-bell-west/scala/ch-2.scala b/challenge-345/roger-bell-west/scala/ch-2.scala
new file mode 100644
index 0000000000..193e526b91
--- /dev/null
+++ b/challenge-345/roger-bell-west/scala/ch-2.scala
@@ -0,0 +1,56 @@
+import scala.collection.mutable.ListBuffer
+
+object Lastvisitor {
+ def lastvisitor(a: List[Int]): List[Int] = {
+ var seen = new ListBuffer[Int]
+ var ans = new ListBuffer[Int]
+ var minusones = 0
+ for (n <- a) {
+ if (n == -1) {
+ minusones += 1
+ if (minusones <= seen.size) {
+ ans += seen(minusones - 1)
+ } else {
+ ans += -1
+ }
+ } else {
+ n +=: seen
+ minusones = 0
+ }
+ }
+ ans.toList
+ }
+ def main(args: Array[String]) {
+ if (lastvisitor(List(5, -1, -1)) == List(5, -1)) {
+ print("Pass")
+ } else {
+ print("Fail")
+ }
+ print(" ")
+ if (lastvisitor(List(3, 7, -1, -1, -1)) == List(7, 3, -1)) {
+ print("Pass")
+ } else {
+ print("Fail")
+ }
+ print(" ")
+ if (lastvisitor(List(2, -1, 4, -1, -1)) == List(2, 4, 2)) {
+ print("Pass")
+ } else {
+ print("Fail")
+ }
+ print(" ")
+ if (lastvisitor(List(10, 20, -1, 30, -1, -1)) == List(20, 30, 20)) {
+ print("Pass")
+ } else {
+ print("Fail")
+ }
+ print(" ")
+ if (lastvisitor(List(-1, -1, 5, -1)) == List(-1, -1, 5)) {
+ print("Pass")
+ } else {
+ print("Fail")
+ }
+ println("")
+
+ }
+}
diff --git a/challenge-345/roger-bell-west/tests.json b/challenge-345/roger-bell-west/tests.json
new file mode 100644
index 0000000000..fa331d1700
--- /dev/null
+++ b/challenge-345/roger-bell-west/tests.json
@@ -0,0 +1,48 @@
+{
+ "ch-1" : [
+ {
+ "function" : "peakpositions",
+ "arguments" : [ 1, 3, 2 ],
+ "result" : [ 1 ]
+ },
+ {
+ "arguments" : [ 2, 4, 6, 5, 3 ],
+ "result" : [ 2 ]
+ },
+ {
+ "arguments" : [ 1, 2, 3, 2, 4, 1 ],
+ "result" : [ 2, 4 ]
+ },
+ {
+ "arguments" : [ 5, 3, 1 ],
+ "result" : [ 0 ]
+ },
+ {
+ "arguments" : [ 1, 5, 1, 5, 1, 5, 1 ],
+ "result" : [ 1, 3, 5 ]
+ }
+ ],
+ "ch-2" : [
+ {
+ "function" : "lastvisitor",
+ "arguments" : [ 5, -1, -1 ],
+ "result" : [ 5, -1 ]
+ },
+ {
+ "arguments" : [ 3, 7, -1, -1, -1 ],
+ "result" : [ 7, 3, -1 ]
+ },
+ {
+ "arguments" : [ 2, -1, 4, -1, -1 ],
+ "result" : [ 2, 4, 2 ]
+ },
+ {
+ "arguments" : [ 10, 20, -1, 30, -1, -1 ],
+ "result" : [ 20, 30, 20 ]
+ },
+ {
+ "arguments" : [ -1, -1, 5, -1 ],
+ "result" : [ -1, -1, 5 ]
+ }
+ ]
+}
diff --git a/challenge-345/roger-bell-west/typst/ch-1.typ b/challenge-345/roger-bell-west/typst/ch-1.typ
new file mode 100644
index 0000000000..73894896cd
--- /dev/null
+++ b/challenge-345/roger-bell-west/typst/ch-1.typ
@@ -0,0 +1,33 @@
+#let testresult(pass) = {
+ if pass {
+ text(fill: green, "Pass")
+ } else {
+ text(fill: red, "Fail")
+ }
+}
+
+#let peakpositions(a) = {
+ let out = ()
+ for (i, x) in a.enumerate() {
+ if (i == 0 or x > a.at(i - 1)) and (i == a.len() - 1 or x > a.at(i + 1)) {
+ out.push(i)
+ }
+ }
+ out
+}
+
+Test 1:
+ #testresult(peakpositions((1, 3, 2)) == (1,))
+
+Test 2:
+ #testresult(peakpositions((2, 4, 6, 5, 3)) == (2,))
+
+Test 3:
+ #testresult(peakpositions((1, 2, 3, 2, 4, 1)) == (2, 4))
+
+Test 4:
+ #testresult(peakpositions((5, 3, 1)) == (0,))
+
+Test 5:
+ #testresult(peakpositions((1, 5, 1, 5, 1, 5, 1)) == (1, 3, 5))
+
diff --git a/challenge-345/roger-bell-west/typst/ch-2.typ b/challenge-345/roger-bell-west/typst/ch-2.typ
new file mode 100644
index 0000000000..6ed0784812
--- /dev/null
+++ b/challenge-345/roger-bell-west/typst/ch-2.typ
@@ -0,0 +1,43 @@
+#let testresult(pass) = {
+ if pass {
+ text(fill: green, "Pass")
+ } else {
+ text(fill: red, "Fail")
+ }
+}
+
+#let lastvisitor(a) = {
+ let seen = ()
+ let ans = ()
+ let minusones = 0
+ for n in a {
+ if n == -1 {
+ minusones += 1
+ if minusones <= seen.len() {
+ ans.push(seen.at(minusones - 1))
+ } else {
+ ans.push(-1)
+ }
+ } else {
+ seen.insert(0, n)
+ minusones = 0
+ }
+ }
+ ans
+}
+
+Test 1:
+ #testresult(lastvisitor((5, -1, -1)) == (5, -1))
+
+Test 2:
+ #testresult(lastvisitor((3, 7, -1, -1, -1)) == (7, 3, -1))
+
+Test 3:
+ #testresult(lastvisitor((2, -1, 4, -1, -1)) == (2, 4, 2))
+
+Test 4:
+ #testresult(lastvisitor((10, 20, -1, 30, -1, -1)) == (20, 30, 20))
+
+Test 5:
+ #testresult(lastvisitor((-1, -1, 5, -1)) == (-1, -1, 5))
+