aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--challenge-345/richard-park/apl/LastVisitor.aplf16
-rw-r--r--challenge-345/richard-park/apl/PeakPositions.aplf11
2 files changed, 27 insertions, 0 deletions
diff --git a/challenge-345/richard-park/apl/LastVisitor.aplf b/challenge-345/richard-park/apl/LastVisitor.aplf
new file mode 100644
index 0000000000..c520e95529
--- /dev/null
+++ b/challenge-345/richard-park/apl/LastVisitor.aplf
@@ -0,0 +1,16 @@
+ LastVisitor←{
+ ⎕IO←0
+ LV←{
+ s←⌽⍵⌿⍨0<⍵ ⍝ Seen is reverse of positive integers
+ i←⍳∘≢¨⊆⍨¯1=⍵ ⍝ How many ¯1s in a row seen so far?
+ i←∊s≢⍛⌊i+⌽⍳≢i ⍝ Offset by how many groups of ¯1s seen and cap at how many +ve ints seen so far
+ (s,¯1)[i] ⍝ seen[x] or ¯1
+ }
+⍝ Tests
+ 5 ¯1≢LV 5 ¯1 ¯1:∘∘∘
+ 7 3 ¯1≢LV 3 7 ¯1 ¯1 ¯1:∘∘∘
+ 2 4 2≢LV 2 ¯1 4 ¯1 ¯1:∘∘∘
+ 20 30 20≢LV 10 20 ¯1 30 ¯1 ¯1:∘∘∘
+ ¯1 ¯1 5≢LV ¯1 ¯1 5 ¯1:∘∘∘
+ 'All tests passed.'
+ }
diff --git a/challenge-345/richard-park/apl/PeakPositions.aplf b/challenge-345/richard-park/apl/PeakPositions.aplf
new file mode 100644
index 0000000000..a7da9a2ec6
--- /dev/null
+++ b/challenge-345/richard-park/apl/PeakPositions.aplf
@@ -0,0 +1,11 @@
+ PeakPositions←{
+ ⎕IO←0
+ PP←{⍸1 ¯1⍷1,ׯ2-/⍵}
+⍝ Tests
+ 1,⍛≢PP 1 3 2:∘∘∘
+ 2,⍛≢PP 2 4 6 5 3:∘∘∘
+ 2 4≢PP 1 2 3 2 4 1:∘∘∘
+ 0,⍛≢PP 5 3 1:∘∘∘ ⍝ I think result should be an empty list
+ 1 3 5≢PP 1 5 1 5 1 5 1:∘∘∘
+ 'All tests passed.'
+ }