aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMarshall Lochbaum <mwlochbaum@gmail.com>2020-08-08 15:59:34 -0400
committerMarshall Lochbaum <mwlochbaum@gmail.com>2020-08-08 15:59:34 -0400
commit37a440133d6d1c2118682fd163d8f616f8d712b6 (patch)
treeb29070307d4a0e200e1d2c9885b8a1aa81019ef3 /src
parenta391024132bb9dbb1f89da1243d5631fa29d5593 (diff)
Add Group components as basic functionality
Diffstat (limited to 'src')
-rwxr-xr-xsrc/pr.bqn2
-rw-r--r--src/r.bqn22
2 files changed, 18 insertions, 6 deletions
diff --git a/src/pr.bqn b/src/pr.bqn
index f695e4cb..e930e6c6 100755
--- a/src/pr.bqn
+++ b/src/pr.bqn
@@ -24,7 +24,7 @@ Inc ← {
}
# Required functionality passed in as an argument
-pnam ← ⟨"IsArray", "Type", "Log"⟩∾names⊏˜chr⊐"!+-×÷⋆⌊=≤≢⥊⊑↕⌜`"
+pnam ← ⟨"IsArray","Type","Log","GroupLen","GroupOrd"⟩∾names⊏˜chr⊐"!+-×÷⋆⌊=≤≢⥊⊑↕⌜`"
E_isdef ← (3≤≠)◶⟨0,∧´⟨chr," ","←↩"⟩∊˜¨3⊸↑⟩
diff --git a/src/r.bqn b/src/r.bqn
index 21e281ec..9afb02bf 100644
--- a/src/r.bqn
+++ b/src/r.bqn
@@ -299,17 +299,29 @@ Join←(1≠=)◶⟨∨´1≠=⌜,1⟩◶{
>i<⌜⊸⊏¨l/𝕩
}⍟(0<≠∘⥊)
-Group←{
+_group←{
+ !1==𝕩⋄!∧´Int⌜𝕩⋄!∧´¯1≤𝕩
+ d←(l←GroupLen𝕩)GroupOrd𝕩
+ i←0⋄(𝔽{𝕩⋄(i↩i+1)⊢i⊑d}⌜∘↕)⌜l
+}
+GroupInds←{
+ ! IsArray 𝕩
+ G←⊢_group
+ (1<≡)◶G‿((<<⟨⟩)⥊⊸∾⌜⌜´G⌜)𝕩
+}
+GroupGen←{
! IsArray 𝕩
- Chk←{!1==𝕩⋄!∧´Int⌜𝕩⋄!∧´¯1≤𝕩⋄≠𝕩}
- l←(1<≡)◶Chk‿{!1==𝕩⋄Chk⌜𝕩}𝕨
+ m←1<≡𝕨
+ l←m◶≠‿{!1==𝕩⋄≠⌜𝕩}𝕨
! l≤○≠≢𝕩
! ∧´l=l≠⊸↑≢𝕩
- (𝕨⊸=/𝕩˜)⌜↕1+¯1⌈´⚇1𝕨
+ 𝕨m◶(⊏⟜𝕩_group⊣)‿{
+ ⊏⟜(𝕩⥊˜⟨×´l⟩∾(≠l)Cell𝕩)⌜ +⌜⌜´ (⌽×`⟨1⟩∾⌽1↓l) × ⊢_group⌜𝕨
+ }𝕩
}
∾ ↩ Join ⊘ JoinTo
-⊔ ← Group⟜(↕≠⚇1) ⊘ Group
+⊔ ← GroupInds ⊘ GroupGen
Pick1←{
! 1==𝕨