Excellent explanations of the use of &. from Mike Day & Raul. Mike's explanation of "multiplication the hard way" using logs really helped clear up what is going on with &.
3*4 12 ^.^:_1 (^.3)+^.4 12 3+&.^.4 12 3 4 5 + &.^. 4 5 6 12 20 30 Now to examine Raul's solution: ,.&.":&.>a ┌───┬─────┬───┬───────┬───┬─┐ │1 0│3 4 5│6 4│5 6 4 2│1 1│5│ └───┴─────┴───┴───────┴───┴─┘ Trying to replicate Raul's solution, step by step: a 10 345 64 5642 11 5 ]b=. >a NB. Does nothing 10 345 64 5642 11 5 ]c=. ": b NB. Turns into literals 10 345 64 5642 11 5 datatype c literal ]d=. >^:_1 c NB. Box each set of literals ┌───────────────────┐ │10 345 64 5642 11 5│ └───────────────────┘ Uh oh! We lost the individual cells. &. must somehow keep track of the individual cells. What should have happened: ]d=.'10';'345';'64';'5642';'11';'5' NB. Keep as separate literals ┌──┬───┬──┬────┬──┬─┐ │10│345│64│5642│11│5│ └──┴───┴──┴────┴──┴─┘ ]e =. ,. each d NB. Columnize each set of literals ┌─┬─┬─┬─┬─┬─┐ │1│3│6│5│1│5│ │0│4│4│6│1│ │ │ │5│ │4│ │ │ │ │ │ │2│ │ │ └─┴─┴─┴─┴─┴─┘ Finally: ": ^:_1 each e NB. the inverse of ": (format, or convert to literals) is ". (Do, or execute) ┌───┬─────┬───┬───────┬───┬─┐ │1 0│3 4 5│6 4│5 6 4 2│1 1│5│ └───┴─────┴───┴───────┴───┴─┘ Finally, Mike Day's explanation of R. E Boss' cool 'automatic magnitude 'solution, which didn't require converting to literals and back. 10 #. ^:_1 each 10 345 64 5642 11 5 ┌───┬─────┬───┬───────┬───┬─┐ │1 0│3 4 5│6 4│5 6 4 2│1 1│5│ └───┴─────┴───┴───────┴───┴─┘ R. E. Boss' scheme of using the inverse of #. (base) to trick antibase into autmatically sizing the magnitudes is brilliant! That is definitely something I will use again. Skip Skip Cave Cave Consulting LLC On Tue, Feb 27, 2018 at 1:27 AM, Skip Cave <[email protected]> wrote: > Thanks to Raul & R. E. Boss for solutions to my Separating Digits problem. > Either solution works well for my application. However, understanding how > either of them works, is still a challenge for me. > > a=. 10 345 64 5642 11 5 > > > Raul's solution: > > ,.&.":&.> a > ┌───┬─────┬───┬───────┬───┬─┐ > │1 0│3 4 5│6 4│5 6 4 2│1 1│5│ > └───┴─────┴───┴───────┴───┴─┘ > > > My first problem with this is the > which should *unbox* an already > > unboxed a, but instead somehow boxes it. > > > Not only that, but I know ": turns numerics into literal text characters. > > > datatype > ":&.> a > > literal > > However in this case, after unboxing the ,. the literals are somehow > turned back into > > integers. > > > datatype > ,.&.":&.> a > > integer > > > ?? magic ?? > > > R. E. Boss' solution > > > 10#.^:_1 &.> a > > ┌───┬─────┬───┬───────┬───┬─┐ > │1 0│3 4 5│6 4│5 6 4 2│1 1│5│ > └───┴─────┴───┴───────┴───┴─┘ > > > I have the same issue with the > which should *unbox* an already > > unboxed a, but instead somehow boxes it. > > > Then I can see that this: > > 10#.^:_1 a > > 0 0 1 0 > > 0 3 4 5 > > 0 0 6 4 > > 5 6 4 2 > > 0 0 1 1 > > 0 0 0 5 > > > is the same as this: > > 10 10 10 10 #: a > > 0 0 1 0 > > 0 3 4 5 > > 0 0 6 4 > > 5 6 4 2 > > 0 0 1 1 > > 0 0 0 5 > > So this: > > 10#.^:_1 &.> a > > ┌───┬─────┬───┬───────┬───┬─┐ > > │1 0│3 4 5│6 4│5 6 4 2│1 1│5│ > > └───┴─────┴───┴───────┴───┴─┘ > > Should be the same as this: > > > > 10 10 10 10 #: &.> a > > |length error > > | 10 10 10 10 #:&.>a > > > But it's not! ?? > > > > Skip > > > > > > > Skip Cave > Cave Consulting LLC > > On Sun, Feb 25, 2018 at 1:17 PM, Skip Cave <[email protected]> > wrote: > >> how can I take a vector of integers: >> >> a=. 10 345 64 5642 11 5 >> >> and separate them into their individual digits (integers): >> >> sep a >> >> ┌───┬─────┬───┬───────┬───┬─┐ >> >> │1 0│3 4 5│6 4│5 6 4 2│1 1│5│ >> >> └───┴─────┴───┴───────┴───┴─┘ >> >> ? >> >> Skip >> > > ---------------------------------------------------------------------- For information about J forums see http://www.jsoftware.com/forums.htm
