[Jprogramming] Pad Arrays for XORing
'Pascal Jasmin' via Programming
programming at jsoftware.com
Thu Dec 4 01:11:05 UTC 2014
,: will pad whatever side is shortest
(i.5) ,: i.3
0 1 2 3 4
0 1 2 0 0
for xor
(i.5) (22 b.)/@:,: i.3
0 0 0 3 4
----- Original Message -----
From: Jon Hough <jghough at outlook.com>
To: "programming at jsoftware.com" <programming at jsoftware.com>
Cc:
Sent: Wednesday, December 3, 2014 7:56 PM
Subject: [Jprogramming] Pad Arrays for XORing
If I want to XOR two arrays (~:), I run into a problem if the two arrays are of different length.
So before XORing I use my "pad" dyadic verb which pads zeros onto the front of the right argument (which is assumed to be the shorter array).
pad =: ((#&0)@:(([: # [) - ([: # ]))) , ]
I imagine this problem is common, so is there a standard verb to do this? I think my verb is not the most elegant, and it has the deficiency of assuming the right argument is the shorter.
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm
More information about the Programming
mailing list