Interesting problem.
1s in 1 to 9: 1
1s in 10 to 99: 20 = 10 + 10*1
1s in 100 to 999: 300 = 100 + 10*20
1s in 1000 to 9999: 4000 = 1000 + 10*300
1s in the naturals below 10^p: (p-1)*10^p-1
But I am fairly certain this does not apply for non-integral p. Not sure
if a closed-form solution is possible; I think you need >:<.10^.n iterations.
-E
On Mon, 17 Jan 2022, Skip Cave wrote:
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
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm