Hello,Suppose that one has a large list and wants to quickly find the firstelement matching a given condition. This condition typically will bemet in the first few elements, so it’s not efficient to scan the entirelist.Is there any easy way to efficiently acheive this search without havingto guess how much to truncate the list?q)r:(prd 8#10)?1fq)\t 0N!first r where 0.9<r0.9543722575q r where></r0.9543722575q>
Hi Josh,
If we’re sure the condition will be satisfied quickly, we can iterate with ‘over’ so that it increments indices and stops when the condition is satisfied:
q)\t 0N!r {count[y]&z+x>=y z}[0.9;r]/[0]
0.9672398
0
However, per iteration, this is much slower than the vectorised comparison we get with < or >, so if we end up scanning the entire vector it becomes very expensive:
q)r:10000000#r
q)\t 0N!r {count[y]&z+x>=y z}[1.1;r]/[0]
0n
12672
q)\t 0N!first r where 1.1<r
0n
36
Regards
Deividas