Hi,
Thanks Bob, that was the problem. The following works:
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=: +/ T NB. Suffixes of the radix sums
┌─────────────────┬──────────────┬───────────┬────────┬─────┬──┐
│33 30 18 25 35 41│30 18 25 35 41│18 25 35 41│25 35 41│35 41│41│
└─────────────────┴──────────────┴───────────┴────────┴─────┴──┘
f=: (0&{ @: ((0 10) & #:)) @: ] NB. Grab the number of tens in y
g=: +
h=: [
carry=: (f g h)
] C=: carry/ L:0 < \. S
┌──┬──┬──┬──┬──┬──┐
│36│32│20│28│39│41│
└──┴──┴──┴──┴──┴──┘
(> {. C), (10 & | @: }. > C) NB. Read off the summation digits
36 2 0 8 9 1
+/ 10 #. "1 T NB. Sanity check
3620891
Thanks Bob and Raul, I'll be back with more questions :)
Lafras
On Mon, 22 May 2017 at 17:18 robert therriault <[email protected]>
wrote:
> Interesting that my solution only differs from yours in the fifth box
> where I get 31 instead of 32, but irrelevant since it is not correct.
>
> Looking at your original question you wrote
>
> +/ 2 3 4 5 = (((2+3) + 4) + 5)
>
> but actually J would evaluate right to left.
>
> +/ 2 3 4 5 = (2 + (3 + (4 + 5)))
>
> You can see this better with non commutative dyadic verbs such as -
>
> (((2-3) - 4) - 5)
> _10
> (2 - (3 - (4 - 5)))
> _2
> -/ 2 3 4 5
> _2
>
> Is it possible that this is the source of your puzzle?
>
> Cheers, bob
>
>
>
> > On May 22, 2017, at 7:56 AM, Lafras Uys <[email protected]> wrote:
> >
> > Hi Bob,
> >
> > Thanks for your reply. For the sequences,
> >
> > |41|41 35|41 35 25|41 35 25 18|41 35 25 18 30|41 35 25 18 30 33|
> >
> > the expected output is
> >
> > |41|39|28|20|32|36|
> >
> > so that when you read 36 and all the "ones" in reverse, i.e. 3620891, you
> > get the sum of the large numbers, as in,
> >
> > +/ 10 #. "1 T
> >
> > 3620891
> >
> > It is therefore not sufficient to calculate the carry operations for
> > successive pairs of numbers, the carry operation depends on all prior
> > carried "tens". Hope that makes sense. In other functional languages I
> > would use reduce or a right fold, but / does not seem to behave as a
> fold.
> >
> > Thanks again for taking an interest,
> >
> > Lafras
> >
> > On Mon, 22 May 2017 at 15:52 robert therriault <[email protected]>
> > wrote:
> >
> >> Hi Lafras,
> >>
> >> It sounds like you don't want the whole sum of the carry's just the sum
> of
> >> the last two in each group. When I use your S as you have defined it I
> get
> >>
> >> S
> >> 36 35 26 16 22 32
> >>
> >> then I take the vector overlapping 2 at a time to make a table
> >> 2 ]\ S
> >> 36 35
> >> 35 26
> >> 26 16
> >> 16 22
> >> 22 32
> >>
> >> then I apply carry on each row
> >> 2 ([: carry/"1 ]\ ) S
> >> 38 29 18 23 34
> >>
> >> Is this what you had in mind?
> >>
> >> Cheers, bob
> >>
> >> ps. (you are the first Lafras I have met. Cool name :-) )
> >>
> >>
> >>> On May 22, 2017, at 2:50 AM, Lafras Uys <[email protected]> wrote:
> >>>
> >>> L:0 < \ S
> >>
> >> ----------------------------------------------------------------------
> >> 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