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

Reply via email to