Oh. I was still thinking in terms of i. . If you want to do something really
sparse it would be best to just use a rank zero verb.

By the way, the solution I gave is entirely wrong. It is more of a proof of
concept than intended for use, and is corrected as follows:
Calculate sum of (+!) of digits for each of i.n

   fac=.3 :0 NB. sums up to (x&*)10^y, with leading zeros
r=.([:,f&(+/))^:y 0
:
(x{.f) ,@:(+/) fac y
)
   d=."."0@":n
   (+/\ _1|.!.0 {&f d) ;@:(+/&.>) (fac&.>/ d,:i.-#d)

This doesn't account for leading zeros, but they are easy to correct for.

Marshall


-----Original Message-----
From: [email protected]
[mailto:[email protected]] On Behalf Of R.E. Boss
Sent: Tuesday, September 07, 2010 8:44 AM
To: 'Programming forum'
Subject: Re: [Jprogramming] splitting stuff into digits the way where you
don't split it into digits

Can you give a working example of your proposal, e.g. on 1e5 ?...@$ 1e8  ?


Apart from that, the question is theoretical since it seems not too
difficult to prove that 85837 408297 are the only integers fulfilling the
conditions.


R.E. Boss


> -----Oorspronkelijk bericht-----
> Van: [email protected] [mailto:programming- 
> [email protected]] Namens Marshall Lochbaum
> Verzonden: maandag 6 september 2010 22:33
> Aan: 'Programming forum'
> Onderwerp: Re: [Jprogramming] splitting stuff into digits the way 
> where you don't split it into digits
> 
> The applicability is a bit of a problem, but you can offset it with 
> clever working in bases.
> Let lsf n give list of sums of factorials up to 10^n:
>    nexp=.(*10...@-@#) d=."."0@": n  NB. Expanded form (i.e. 
> 1234-->1000
> 200
> 30 4)
>    start=.+/\ {&f d  NB. Sums for starting values (ie.
> 1***,12**,123*,1234)
>    start +&(+/) lsf"0 nexp
> 
> That should do it.
> 
> Marshall
> 
> 
> -----Original Message-----
> From: [email protected] 
> [mailto:[email protected]] On Behalf Of R.E. Boss
> Sent: Monday, September 06, 2010 3:25 PM
> To: 'Programming forum'
> Subject: Re: [Jprogramming] splitting stuff into digits the way where 
> you don't split it into digits
> 
> Nice solution. Not only faster, but also leaner.
> 
>    rank '+/"1 {&f 10&#.^:_1 i.1e6';'([:,f&(+/))^:5 f'
> +----+-----+-----+----+
> |rank|tm*sz|time |size|
> +----+-----+-----+----+
> | 1  |94.60|14.89|6.35|
> +----+-----+-----+----+
> | 0  | 1.00| 1.00|1.00|
> +----+-----+-----+----+
> 
>    -:/".&.> '+/"1 {&f 10&#.^:_1 i.1e6';'([:,f&(+/))^:5 f'
> 1
> 
> However, only applicable if the universe is i.10^n.
> 
> 
> R.E. Boss
> 
> 
> > -----Oorspronkelijk bericht-----
> > Van: [email protected] [mailto:programming- 
> > [email protected]] Namens Marshall Lochbaum
> > Verzonden: zondag 5 september 2010 23:58
> > Aan: Programming forum
> > Onderwerp: [Jprogramming] splitting stuff into digits the way where 
> > you don't split it into digits
> >
> > 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

----------------------------------------------------------------------
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