aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMohammad Sajid Anwar <mohammad.anwar@yahoo.com>2025-02-03 11:29:43 +0000
committerMohammad Sajid Anwar <mohammad.anwar@yahoo.com>2025-02-03 11:29:43 +0000
commit0a2c7d626adb83617b1f4560ee5aaeae07a68989 (patch)
tree1f4469bb19795eda78ab0ba89c6d79080a2c8893
parentc071bd123ebc086768c2b2e0d1d5b887ecf6585f (diff)
downloadperlweeklychallenge-club-0a2c7d626adb83617b1f4560ee5aaeae07a68989.tar.gz
perlweeklychallenge-club-0a2c7d626adb83617b1f4560ee5aaeae07a68989.tar.bz2
perlweeklychallenge-club-0a2c7d626adb83617b1f4560ee5aaeae07a68989.zip
- Added solutions by Richard Park.
-rw-r--r--challenge-307/richard-park/apl/CheckOrder.aplf12
-rw-r--r--challenge-307/richard-park/apl/FindAnagrams.aplf19
2 files changed, 31 insertions, 0 deletions
diff --git a/challenge-307/richard-park/apl/CheckOrder.aplf b/challenge-307/richard-park/apl/CheckOrder.aplf
new file mode 100644
index 0000000000..4958c6dbbc
--- /dev/null
+++ b/challenge-307/richard-park/apl/CheckOrder.aplf
@@ -0,0 +1,12 @@
+ CheckOrder←{
+⍝ Return indices of major cells in ⍵ that differ from ⍵ sorted ascending
+ ⎕IO←0 ⍝ Set index origin to 0 to match examples
+⍝ Simple vector (list) case, return indicies of elements in ⍵
+ sorted←⍵[⍋⍵]
+ ⍸⍵≠sorted
+⍝ General array case
+⍝ https://aplwiki.com/wiki/Total_array_ordering
+⍝ https://aplwiki.com/wiki/Leading_axis_theory
+ sorted←(⍋⊂⍛⌷⊢)⍵
+ ⍸⍵(≢⍤¯1)sorted
+ }
diff --git a/challenge-307/richard-park/apl/FindAnagrams.aplf b/challenge-307/richard-park/apl/FindAnagrams.aplf
new file mode 100644
index 0000000000..0734828a0b
--- /dev/null
+++ b/challenge-307/richard-park/apl/FindAnagrams.aplf
@@ -0,0 +1,19 @@
+ FindAnagrams←{
+⍝ Return count of words in list after removing neighbouring words that are anagrams
+⍝ Anagrams are identical after sorting: ≡⍥∆
+ ∆←{⍵[⍋⍵]}
+ +/2≢⍥∆/(⊂''),⍵
+⍝ Above computes the count as simply as possible.
+⍝ To drop leading consecutive anagrams as described, we rotate our selection mask
+ ⍵⌿⍨1⌽2≢⍥∆/(⊂''),⍵
+⍝ (⊂''),words ⍝ Prepend with empty so windowed-reduction (2F/⍵) marks initial group
+⍝ ┌┬────┬────┬────┬──┬──┐
+⍝ ││abba│baba│aabb│ab│ab│
+⍝ └┴────┴────┴────┴──┴──┘
+⍝ 2≢⍥∆/(⊂''),words ⍝ Mark boundaries of groups of consecutive anagrams
+⍝ 1 0 0 1 0
+⍝ words⌿⍨1⌽2≢⍥∆/(⊂''),words ⍝ Rotate (with wrapping) to find the ends of groups (words to keep)
+⍝ ┌────┬──┐
+⍝ │aabb│ab│
+⍝ └────┴──┘
+ }