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