This is a working solution. Not pretty, but it gets the job done.
onesList =: (0<{.)`($:@}. + ((10 ^ <:@#) * 1<{.) + ((1 + 10 #. }.) * 1={.) + <:@# * {. * 10 ^ 2 -~ #)@.(1<#)
ones =: 10 onesList@:(#.^:_1)"0 ] NB. tests ones 30 521 13 213 That was easy. Now for the “inverse:” dlog =: 10&^. flog =: <.&.dlog NB. no $: inside of DDs dekasect =: {{ 0 dekasect y;0;0;(* flog@<.@dlog) flog y : 'N offset start step' =: y if. step < 1 do. offset return. end. stips =. start + steps =. step * i. 11 stops =. (x * steps) + ones stips totals =. stops + ones offset - start idx =. stops I. N if. idx < # steps do. if. N = idx { totals do. idx { stips return. end. end. (x + idx = 2) dekasect N; ((;~offset&+) (<:idx) { steps), < step % 10 }} NB. test dekasect 213 530 It doesn’t return the smallest/largest one but the earliest one found. That’s been fun. Am 17.01.22 um 20:18 schrieb Skip Cave:
If I want to find the number of '1' digits in an integer, I can design a verb c1, (count ones) to do that: *c1=.{{+/1=10#.^:_1]y}}"0* Test it: * c1 10* *1* * c1 11* *2* * c1 103416* *2* * c1 56161764121* *4* I can also find the total number of '1' digits in a list of sequential integers from 1 to n: * to=:[+i.@:>:@-~ * * +/c1 1 to n=.30* *13* * +/c1 1 to n=.521* *213* My question is: Given the total number of 1s in a sequence from 1 to n, what is n? A verb F(x) should return the final integer n, in the sequential list 1 to n, that contains x ones. Using the previous results as an example: * F 213 *NB. A sequence 1 to n has 213 ones. What is n? *521 *NB. The sequence 1 to 521 has 213 ones What are some options to design the verb F? 1) Explicit 2) Implicit 3) Iteration 4) Recursion Skip Cave Cave Consulting LLC ---------------------------------------------------------------------- For information about J forums see http://www.jsoftware.com/forums.htm
-- ---------------------- mail written using NEO neo-layout.org ---------------------------------------------------------------------- For information about J forums see http://www.jsoftware.com/forums.htm