Home › Forums › kdb+ › Challenge 3 The Runner-Up › Re: Challenge 3 The Runner-Up
-
Indexing into the descending sorted list of distinct scores works pretty well ok
q)f:{desc[distinct x]1} q)l:4 7 9 7 2 8 9 q)f[l] 8
EDIT: type and scale can matter here when looking for the best option. A version of the original suggestion outperforms mine in a lot of cases
q)f1:{max x except max x} // original suggested solution q)f2:{desc[distinct x]1}
q)l:4 7 9 7 2 8 9
q)t:10000 f1 l
9
q)t:10000 f2 l
16q)longs:100000?100 //scale up
q)t:100 f1 longs
38
q)t:100 f2 longs //lots of duplicates gives the “distinct” solution an advantage
19q)floats:100000?100f // change type to float
q)t:100 f1 floats
392
q)t:100 f2 floats //advantage disappears when there are few duplicate entries
707