Better HN
topnewbestaskshowjobs
Log inSign up

qesa

2 karma · joined May 25, 2017 (9y ago) · 2 submissions

Submissions

comment 9y ago · link · parent

I actually had it wrong in mine. Wasn't paying attention and had the dictionary the wrong way around. Probably would have been more obvious with the char since you can't sum them...

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

comment 9y ago · link · parent

Using the file from the original,

    1#desc sum each group (!/) (" II";"\t") 0: `:tsvfile
Took about 3 seconds, 2.5 of which was reading the file

EDIT:

    q)\ts d: (!/) (" II";"\t") 0: `:tsvfile
    2489 134218576
    q)\ts 1#desc sum each group d
    486 253055104