aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarshall Lochbaum <mwlochbaum@gmail.com>2020-08-06 14:47:31 -0400
committerMarshall Lochbaum <mwlochbaum@gmail.com>2020-08-06 15:00:23 -0400
commit6c6aa96dc7c6cf76e4de55e6389716f4b082b7b7 (patch)
treeae0f426ffd29c898a58160e9496bae18f8cfd003
parent413fa9a4a780489c1ad2a5ceb7835493e86b5f8c (diff)
Implement Grade without pervasion
-rw-r--r--impl.bqn29
1 files changed, 15 insertions, 14 deletions
diff --git a/impl.bqn b/impl.bqn
index 9bcb77da..fafbad43 100644
--- a/impl.bqn
+++ b/impl.bqn
@@ -77,6 +77,21 @@ Cmp ← +○IsArray◶⟨
Cc˜0
}
+_grade←{
+ ! 1≤=𝕩
+ m←1×´1 Cell 𝕩
+ cc←m 𝔽○(⊑⟜(⥊𝕩)) _getCellCmp 0
+ GT←Cc>0˜
+ l←≠𝕩
+ B←l⊸≤◶⊢‿l
+ (↕l){
+ i←-d←𝕨 ⋄ j←ei←ej←0
+ e←3 ⋄ c←⟨GT○(⊑⟜(m⊸ר⍟(1-m=1)𝕩)),0,1,2⟩
+ N←{i↩d+𝕨⋄ej↩B d+ei↩B j↩d+𝕩⋄e↩l≤j⋄i R j}
+ R←{𝕨e◶c𝕩}◶{e+↩2×ei=i↩1+𝕨⋄𝕨}‿{e+↩ej=j↩1+𝕩⋄𝕩}‿N
+ {(i R j)⊑𝕩}⟜𝕩¨𝕩
+ }´(2⋆ni-1+⊢)¨↕ni←-⌊-2 Log l+l=0
+}
Indices←{
! 1==𝕩
@@ -376,20 +391,6 @@ _binSearch ← {
1+(𝕩+1)R ¯1
}⍟(0⊸<)
}
-_grade←{
- ! 1≤=𝕩
- m←×´1 Cell 𝕩
- cc←m 𝔽○(⊑⟜(⥊𝕩)) _getCellCmp 0
- GT←Cc>0˜
- l←≠𝕩
- (↕l){
- i←-d←𝕨 ⋄ j←ei←ej←0
- e←3 ⋄ c←⟨GT○(⊑⟜(m×⍟(≠⟜1)𝕩)),0,1,2⟩
- N←{i↩d+𝕨⋄ej↩l⌊d+ei↩l⌊j↩d+𝕩⋄e↩j≥l⋄i R j}
- R←{𝕨e◶c𝕩}◶{e+↩2×ei=i↩1+𝕨⋄𝕨}‿{e+↩ej=j↩1+𝕩⋄𝕩}‿N
- {𝕩⋄i R j}¨⊸⊏𝕩
- }´2⋆⌽↕⌈2 Log 1⌈l
-}
_bins←{
c←1-˜=𝕨
! 0≤c