I don't have time to walk through an explanation of this, at the moment, but
here's an arithmetic solution (instead of a text-representation solution.)


   NB. the numbers need not be boxed
   ]aaa=: 2 7 $ 6 30 1 17 119 118 116 63  2 5 17 103  14   1
 6 30 1 17 119 118 116
63  2 5 17 103  14   1

   magnitude=: 10^ 1>. [: >. 10^.]

   magnitude {: aaa   NB. how much to shift each, in this example
100 10 10 100 1000 100 10

   join=: ]+ [* magnitude@]

   join/ aaa
663 302 15 1717 119103 11814 1161



On Thu, Jul 14, 2011 at 11:49 PM, PackRat <[email protected]> wrote:

> I wish to append the digits of two numbers to form a new number:
>  12  345  -->  12345
>
> I'm sure this is elementary, but I'm currently stumped.  Here's some
> data (which in reality would have been read in from a CSV file and then
> transposed):
>
> aa=. 2 7 $ 6;30;1;17;119;118;116;63;2;5;17;103;14;1
>
> +--+--+-+--+---+---+---+
> |6 |30|1|17|119|118|116|
> +--+--+-+--+---+---+---+
> |63|2 |5|17|103|14 |1  |
> +--+--+-+--+---+---+---+
>
> Then I pulled out the numeric data pairs, converted them to literals,
> and appended them:
>
> b=. ( ": every 0{aa ) ,. ( ": every 1{aa )
>
> 6  63
> 30 2
> 1  5
> 17 17
> 119103
> 11814
> 1161
>
> Just for visual purposes here (NOT in J!), I substituted * for spaces,
> to show what's happening:
>
> 6**63*
> 30*2**
> 1**5**
> 17*17*
> 119103
> 11814*
> 1161**
>
> However, what I want to end up with is this, no spaces, different
> lengths:
>
> 663
> 302
> 15
> 1717
> 119103
> 11814
> 1161
>
> To attempt to do this, I did the following:
>
> spc=. ' ' E. every b
>
> 0 1 1 0 0 1
> 0 0 1 0 1 1
> 0 1 1 0 1 1
> 0 0 1 0 0 1
> 0 0 0 0 0 0
> 0 0 0 0 0 1
> 0 0 0 0 1 1
>
> keepmask=. (0 = spc)
>
> 1 0 0 1 1 0
> 1 1 0 1 0 0
> 1 0 0 1 0 0
> 1 1 0 1 1 0
> 1 1 1 1 1 1
> 1 1 1 1 1 0
> 1 1 1 1 0 0
>
> I thought that the following would accomplish what I wanted, but it
> does NOT:
>
> nospc=. keepmask # each b
>
> +-+-+-+-+-+-+
> |6| | |6|3| |
> +-+-+-+-+-+-+
> |3|0| |2| | |
> +-+-+-+-+-+-+
> |1| | |5| | |
> +-+-+-+-+-+-+
> |1|7| |1|7| |
> +-+-+-+-+-+-+
> |1|1|9|1|0|3|
> +-+-+-+-+-+-+
> |1|1|8|1|4| |
> +-+-+-+-+-+-+
> |1|1|6|1| | |
> +-+-+-+-+-+-+
>
> Essentially, this puts me right back where I started, without
> accomplishing anything.  I thought it would be a very straightforward
> process to append the digits of two numbers--it's sort of the reverse
> of what was discussed here recently.  The final step, of course, is to
> convert the new literal back into a number (but that part's easy!).
>
> I appreciate any help with this--thanks in advance!
>
> Harvey
>
> ----------------------------------------------------------------------
> 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