It looks pretty to me. Linda will like your treatment of negatives.
brAai =: (**|.@:(2| [:}:<.@-:^:a: )&.|:@:|)`,@.(0-:])
brAai i:3
_1 _1
_1 0
0 _1
0 0
0 1
1 0
1 1
How would you handle two's-complement negatives?
Verb bri17 is neat. You could use & instead of &. .
Kip
On 12/28/2011 3:06 AM, Aai wrote:
> Making it uglier and uglier:
>
> ((**#:@:|)-:(**|.@:(2| [:}:<.@-:^:a: )&.|:@:|)`,@.(0-:])) 0
> 1
> ((**#:@:|)-:(**|.@:(2| [:}:<.@-:^:a: )&.|:@:|)`,@.(0-:])) _1
> 1
> ((**#:@:|)-:(**|.@:(2| [:}:<.@-:^:a: )&.|:@:|)`,@.(0-:])) i:5
> 1
> ((**#:@:|)-:(**|.@:(2| [:}:<.@-:^:a: )&.|:@:|)`,@.(0-:])) 0j_13
> 1
>
> note: I use here my preferred representation of negative binaries.
>
>
> For inversion I would use:
>
>
> (++:)/&.|. "1
>
> bri=: (2 p.~ |.)"1
>
> bri17=: (++:)/&.|. "1
>
> (bri=bri17) 1,5e3?.@$2x
> 1
>
>
> ts 'bri17 B' [B=.1x,5e3?.@$2
> 0.048458 44608
> ts 'bri B'
> 6.51718 1.18346e7
>
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm