Writing a script to test your code is almost as much fun as trying to solve the problem.
Here's a script. F always provides the same result. G will never (almost never) have the same result. f=: 13 :'(y,4)$?.(4*y)#4' ]A=:f 4 g=: 13 :'(y,4)$?(4*y)#4' ]B=:g 5 Run it once. f=: 13 :'(y,4)$?.(4*y)#4' ]A=:f 4 2 0 2 0 3 1 2 0 0 2 2 2 1 1 0 3 g=: 13 :'(y,4)$?(4*y)#4' ]B=:g 5 2 2 2 3 2 0 3 3 0 3 3 1 3 3 3 3 2 1 2 3 After I ran it, I ran it again. f=: 13 :'(y,4)$?.(4*y)#4' ]A=:f 4 2 0 2 0 3 1 2 0 0 2 2 2 1 1 0 3 g=: 13 :'(y,4)$?(4*y)#4' ]B=:g 5 0 1 1 3 2 3 1 1 3 1 2 3 1 0 0 2 2 0 3 1 Now I can make two samples to test my code, which I am ready to try and write. Linda -----Original Message----- From: [email protected] [mailto:[email protected]] On Behalf Of Ben Gorte - CITG Sent: Thursday, July 10, 2014 4:18 AM To: [email protected] Subject: Re: [Jprogramming] Comaring Arrays Sort will produce the same result for both arrays. ]A=:4 4$3 2 1 0 1 0 3 2 2 3 0 1 0 0 0 0 3 2 1 0 1 0 3 2 2 3 0 1 0 0 0 0 ]B=:4 4$2 3 0 1 3 2 1 0 1 0 3 2 0 0 0 0 2 3 0 1 3 2 1 0 1 0 3 2 0 0 0 0 (/:~A) -: /:~B 1 Ben ________________________________________ From: [email protected] [[email protected]] on behalf of Jon Hough [[email protected]] Sent: Thursday, July 10, 2014 10:07 To: [email protected] Subject: [Jprogramming] Comaring Arrays The following two 4x4 arrays are rearrangements of each other's rows. 3 2 1 0 1 0 3 2 2 3 0 1 0 0 0 0 2 3 0 1 3 2 1 0 1 0 3 2 0 0 0 0 I would like to know a way to acknowledge two arrays as being rearrangements of each other. Eventually my goal is to compare long lists of such arrays and nub out duplicates - duplicates being rearrangements. The only way I can think to do this is to cycle through all permutations of the row of one of the arrays and test for equality with the other array, using A. . Of course, there are 24 permutations to test for 4x4 arrays, but obviously for bigger arrays things get worse. Is there a faster way to check two arrays are (ignoring row permutations) equivalent? ---------------------------------------------------------------------- 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
