Joined 9 years ago
With the reverse thrown in to switch the key/value around we get the correct answer
q) 1#desc sum each group (!/) reverse (" II";"\t")0:`:1gram 2006| 22569013
k) {(&x=|/x)#x}@+/'=:!/|(" II";"\t")0:`:1gram (,2006i)!,22569013i
k)e: 4 5 8 9 6!"ABBCA" k){(&x=|/x)#x}@+/'=:e (,"B")!,13
1#desc sum each group (!/) (" II";"\t") 0: `:tsvfile
EDIT:
q)\ts d: (!/) (" II";"\t") 0: `:tsvfile 2489 134218576 q)\ts 1#desc sum each group d 486 253055104
With the reverse thrown in to switch the key/value around we get the correct answer
or Works the same for the simple example