![]() |
Indices of Occurrences | Index << >> |
As part of the code that I’ll be presenting at LambdaConf, I have the following idiomatic problem that appears in more than one place. For vectors A and B , compute P and C : M←A∘.=B ⋄ P←A⌿⍨+/M ⋄ C←(≢B)|⍸,M The problem with the above solution is the quadratic space and time to compute M . Essentially, what I’m looking to get is a pattern like this: P: 0 0 0 1 1 1 1 2 2 2 2 3 3 3 3 C: 1 2 3 4 5 6 7 1 2 3 4 9 8 7 6 [Assume that A and B are integer vectors and that A is sorted and free of duplicates.] E-mail from Aaron Hsu, 2018-05-23. |