The original problem was actually to find numbers such that the sum of (+!)
of the digits was equal to the number. So:
   f=.(+!)i.10
   r=.([:,f&(+/))^:6 f
   r=.r - 6,(9*10^i.7)#(i._7)
   (#~ =&r) i. 1e7
85837 408297

Because 
   (+!) 8 5 8 3 7
40328 125 40328 9 5047
   +/ (+!) 8 5 8 3 7
85837
   
This is really a digit splitting problem, and the next best solution turns
out to be something like the
   f=.(+!)i.10
   r=. +/"1 {&f 10&#.^:_1 i.1e7
   r=.r - 6,(9*10^i.7)#(i._7)
   (#~ =&r) i. 1e7
85837 408297

That I was comparing it to. However, this one is a lot faster.

Marshall

-----Original Message-----
From: [email protected]
[mailto:[email protected]] On Behalf Of Don Guinn
Sent: Sunday, September 05, 2010 7:02 PM
To: Programming forum
Subject: Re: [Jprogramming] splitting stuff into digits the way where you
don't split it into digits

Seems to be a minor problem. It doesn't calculate the n+!n for n>10.

   f=.(+!)i.10

   r=.([:,f&(+/))^:6 f

   r=.r - 6,(9*10^i.7)#(i._7)
   15{.r
1 2 4 9 28 125 726 5047 40328 362889 3 4 6 11 30
   (+!)i.15
1 2 4 9 28 125 726 5047 40328 362889 3.62881e6 3.99168e7 4.79002e8 6.22702e9
8.71783e10
   (+!)i.15x
1 2 4 9 28 125 726 5047 40328 362889 3628810 39916811 479001612 6227020813
87178291214


On Sun, Sep 5, 2010 at 4:58 PM, Marshall Lochbaum <
[email protected]> wrote:

> Thought I would let everyone know about the alternate approach I just 
> found to the sums of factorials of digits problem:
>
>
>
>   f=.(+!)i.10
>
>   r=.([:,f&(+/))^:6 f
>
>   r=.r - 6,(9*10^i.7)#(i._7)
>
>
>
> This generates the sum of the digit plus the factorial for each of 
> i.1e6
>
> This way, you don't have to actually work starting with i.1e6. By 
> modifying the 6s and 7s, you can generate any list of the form 10^n, 
> although 1e7 is about the limit in terms of memory.
>
>
>
> It is also faster than the other method:
>
>
>
>   6!:2 '([:,f&(+/))^:6 f=.(+!)i.10'
>
> 0.205724
>
>   6!:2 '+/"1 {&f 10&#.^:_1 i.1e6'
>
> 0.378998
>
>
>
> Where each has an error based on the number of leading zeros 
> (corrected for in the last line of the script above).
>
>
>
> You can probably also generate length 10^2^n by taking ([:,+/~)^:n f, 
> but that is a bit ridiculous.
>
>
>
> Marshall
>
> ----------------------------------------------------------------------
> For information about J forums see http://www.jsoftware.com/forums.htm
>
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to