Here's my take on what I think you are asking for: 10&#.inv 41 35 4 1 3 5 +//. 10&#.inv |.41 35 3 9 1 2 {. +//. 10&#.inv |.41 35 3 9 (2 {. +//.)&. (10&#.inv) |.41 35 39 carry=: (2 {. +//.)&. (10&#.inv)@|. T=: 6 6 $ 3 7 1 0 7 9 4 6 3 7 6 9 7 4 3 2 4 9 9 1 9 4 2 2 2 3 0 6 7 5 +/ |. "1 T 43 33 19 17 28 28 S=: +/ |. "1 T carry/ L:0 < \ S ┌──┬──┬──┬──┬──┬──┐ │43│33│19│17│28│28│ └──┴──┴──┴──┴──┴──┘ carry/\ S 43 33 19 17 28 28
Whether this relates to PE 13 or not, I am not sure. But I hope some of this might help. Thanks, -- Raul On Mon, May 22, 2017 at 5:50 AM, Lafras Uys <lafr...@gmail.com> wrote: > Hi, > > I am working through Project Euler to learn J. For PE 13 I am trying to > implement a carry function. For example: > > 41 carry 35 = 39 NB. Add the tens from 41 to the ones of 35 > > This is what I have so far: > > NB. "Large" numbers > > ] T=: 6 6 $ 3 7 1 0 7 9 4 6 3 7 6 9 7 4 3 2 4 9 9 1 9 4 2 2 2 3 0 6 7 5 > 8 9 2 6 9 7 > > 3 7 1 0 7 9 > > 4 6 3 7 6 9 > > 7 4 3 2 4 9 > > 9 1 9 4 2 2 > > 2 3 0 6 7 5 > > 8 9 2 6 9 7 > > < \ S=: +/ |. "1 T NB. Suffixes of the reversed radix sums > > +--+-----+--------+-----------+--------------+-----------------+ > > |41|41 35|41 35 25|41 35 25 18|41 35 25 18 30|41 35 25 18 30 33| > > +--+-----+--------+-----------+--------------+-----------------+ > > f=: (0&{ @: ((0 10) & #:)) @: [ NB. Grab the number of tens in x > > g=: + > > h=: ] > > carry=: (f g h) > > carry/ L:0 < \ S > > +--+--+--+--+--+--+ > > |41|39|32|27|40|46| > > +--+--+--+--+--+--+ > > > My carry verb works fine for the first two numbers, however as soon as > there are three or more numbers it looks like all the "tens" from x is > added to y, e.g. 4+3+25 = 32 instead of 28. My understanding is that `/` > acts like a fold, maintaining an accumulator as in +/ 2 3 4 5 = (((2+3) + > 4) + 5) so that the left hand side is the result of the computation to > date. I'm clearly missing something important here. > > > Any comments and help is appreciated, > > > Lafras > ---------------------------------------------------------------------- > For information about J forums see http://www.jsoftware.com/forums.htm ---------------------------------------------------------------------- For information about J forums see http://www.jsoftware.com/forums.htm