aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMohammad Sajid Anwar <Mohammad.Anwar@yahoo.com>2025-10-27 23:11:38 +0000
committerGitHub <noreply@github.com>2025-10-27 23:11:38 +0000
commitbb68a27c32aadb8f9c48241f07d89e018671a410 (patch)
treea7426ea8283e89520c3eff3860059613a870e700
parent8efd49cf24639ce644f3aafb8d88d20e92e3de3b (diff)
parent734114fe0aef9d21b97bcfb9168b6ef700003526 (diff)
downloadperlweeklychallenge-club-bb68a27c32aadb8f9c48241f07d89e018671a410.tar.gz
perlweeklychallenge-club-bb68a27c32aadb8f9c48241f07d89e018671a410.tar.bz2
perlweeklychallenge-club-bb68a27c32aadb8f9c48241f07d89e018671a410.zip
Merge pull request #12935 from rikedyp/master
week 345 in APL
-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.'
+ }