by gwu78 · 9y ago · 0 comments
A 4
B 5
B 8
C 9
A 6
How to solve with only a dict?Regarding the 1gram file at https://storage.googleapis.com/books/ngrams/books/googlebook...
This is the result I got
3| 1742563279
using q)\ts d:(!/)(" II";"\t")0:`:1gram
q)\ts 1#desc sum each group d
1897 134218176
371 238872864
or k)\ts d:(!/)(" II";"\t")0:`:1gram
k)\ts desc:{$[99h=@x;(!x)[i]!r i:>r:. x;0h>@x;'`rank;x@>x]}
k)\ts 1#desc (sum'=:d)
1897 134218176
0 3152
372 238872864
No doubt I must be doing some things wrong.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
or k) {(&x=|/x)#x}@+/'=:!/|(" II";"\t")0:`:1gram
(,2006i)!,22569013i
Works the same for the simple example k)e: 4 5 8 9 6!"ABBCA"
k){(&x=|/x)#x}@+/'=:e
(,"B")!,13