I didn’t do it much differently, conceptually. But instead of binary search (bisection) I split it up in ten buckets (dekasect). Apologies for the bad naming: another greek-latin hybrid, oh my …
I split that way because I wanted to evaluate ones more often on small inputs than large. Didn’t measure if it atcually helps, though. And maybe I should have added an M. in order to memoize? But seno definitively reads better. Am 18.01.22 um 02:54 schrieb Raul Miller:
Your 'ones' is a bit more efficient than the routine I had come up with, so I'll stick with your implementation here. Meanwhile, it's perhaps worth noting I.213=ones i.1000 521 522 523 524 525 526 527 528 529 530 So, building the inverse... it's typical for there to be ten numbers who had n "one digits in the sequence". But, for example, there's no number which has exactly 3 "one digits in the sequence". Ten has 2, eleven has four. But we can find the minimum value which had at least n preceding one digits. Personally, I'd use a binary search here: seno=:{{ if.y=ones y do.y return.end.hi=.2*lo=.y while.y>ones hi do. hi=.2*lo=.hi end. while.hi>lo do. assert. hi<1000 select.*y-ones mid=.<.-:lo+hi+1 case._1 do.if.hi=mid do.lo=.hi break.end.hi=.mid case.0 do.lo=.hi=.mid break. case.1 do.lo=.mid end. end. while.y <: ones lo do.lo=.<:hi=.lo end. NB. maybe too crude... hi }} seno 213 521 ones 521 213 FYI,
-- ---------------------- mail written using NEO neo-layout.org ---------------------------------------------------------------------- For information about J forums see http://www.jsoftware.com/forums.htm