ones1 reads better than the original. factoring out {. and }. really helps. even though it means pairs of factors are “distributed” and one doesn’t immediately see which one is corresponding. if it hadn’t been for having it fit on one line, I had kept the recursive call separate, though.
Am 23.01.22 um 09:06 schrieb Raul Miller:
If you are working with a limited range, you can use I. to conduct the search. For example, ones1=: (1,1&<,1&=,])@{. +/@:* (0:`$:@.(0<#),(10^#),(1+10#.]),#*10^#-1:)@}. ones=: 10 ones1@:(#.inv)"0 ] senO=: ] I.~ [: +/\1+/"1@:=10 #.inv [: i. +:@]^:(> ones)^:_~ Here, I used a golfed version of Hauke Rehr's 'ones' verb in an estimator for a bound on the list length that I needed to search (I shortened it to avoid email line wrap issues). But we could use something else to perform the estimate. The limitation here is that we have to form an intermediate result large enough to search. So you start getting noticeable lag around 3e5 and you probably don't want to go much beyond 1e6 very often. I hope this helps,
-- ---------------------- mail written using NEO neo-layout.org ---------------------------------------------------------------------- For information about J forums see http://www.jsoftware.com/forums.htm