Somehow it feels recursive and a 10 year gap in doing much in J leaves me
with a big black hole.  I would probably start with a nice little Fibonacci
program. This is the kind of question which makes me think "I need a nap".

Hopefully, more later.

Linda 

-----Original Message-----
From: programming-boun...@jsoftware.com
[mailto:programming-boun...@jsoftware.com] On Behalf Of Kip Murray
Sent: Saturday, December 10, 2011 10:07 AM
To: Programming forum
Subject: Re: [Jprogramming] How #: should have been designed

Linda, you may want to look up two's-compliment arithmetic, see

http://en.wikipedia.org/wiki/Two's_complement

Your idea in hcla is nice.  Can you figure out a way to calculate the 
number of 2's required for the left argument?  For example you would 
need four 2's for

     (2 2 2 2 hcla i: 5) -: hc i: 5
  1

On 12/10/2011 3:56 AM, Linda Alvord wrote:
> Kip,  Is this what you are looking for:
>
>
>     hcla=: 13 :'x#:y'
>     ]d=:2 2 2 hcla i:2
> 1 1 0
> 1 1 1
> 0 0 0
> 0 0 1
> 0 1 0
>
>     hcinvla=:hcla^:_1 hcla
>     hcinvla d
> |length error: hcinvla
> |       hcinvla d
>
>      hcla
> #:
>      hcinvJ=:#:^:_1
>      hcinvJ
> #:^:_1
>
>     hcinvJ d
> 6 7 0 1 2
>
>    hcinvla
> #.
>    hcinvla=: 13 :'#.y'
>    hcinvla d
> 6 7 0 1 2
>
> Raul's new improved answer  hc  doesn't appear to deal with the negative
> values. My inverse does the best it can with the data it gets.
>
> My code is mostly from the dictionary. I'm not sure what would be the best
> way to deal with negative binary numbers.  Maybe I'll remember something
> about that a little later.
>
> Linda
>
>
> -----Original Message-----
> From: programming-boun...@jsoftware.com
> [mailto:programming-boun...@jsoftware.com] On Behalf Of Kip Murray
> Sent: Saturday, December 10, 2011 1:02 AM
> To: Programming forum
> Subject: Re: [Jprogramming] How #: should have been designed
>
> Now we need an inverse for Raul's improved #: ("hash colon")
>
>       hc  NB. Raul's improved #:
>    {.@#:@(,: (2 * |))
>
>       hc i: 2
>    1 1 0
>    1 1 1
>    0 0 0
>    0 0 1
>    0 1 0
>
>       hcinv  NB. improvement sought
>    2&#.`(2&#.@}. - 2 ^<:@#)@.{."1
>
>       hcinv hc i: 2
>    _2 _1 0 1 2
>
> On 12/8/2011 2:41 PM, Raul Miller wrote:
> ...
> But this would work just as well, as a model:
>
>       {.@#:@(,:  2 * |)i:2
>    1 1 0
>    1 1 1
>    0 0 0
>    0 0 1
>    0 1 0
> ----------------------------------------------------------------------
> 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