Problem 1740. Find number patterns in rows of a matrix...

So I think this may be a hard one, may be it was only hard for me! So here is what it is, I will give a matrix, with some number of rows by 5 columns, to make it simpler I will not repeat any number in a single row, so all numbers in a single rows are unique. So you need to find up to 2, 3 or 4 numbers that are found in a single row that repeat in other rows and the amount of times they repeat in a given matrix. To make it a little better, you only need to display the rows/numbers that repeat at lease twice or more. Examples are the best way to show what to do:

          %p is the given matrix
          p = [1 2 3 4 5;
               2 3 4 5 1;
               3 4 6 7 8;
               1 2 4 3 5;
               4 6 3 2 1];
          %v is the amount of elements per row that are being checked to see if they repeat in another row
          v = 4;
        %Output:
        out =
             1     2     3     4     4
             1     2     3     5     3
             1     2     4     5     3
             1     3     4     5     3
             2     3     4     5     3
      %So the first to the fourth column are the four number that were found to repeat in rows of matrix p (any and all combination that can appear in the rows of the matrix p). The fifth column is the amount of times the that particular set of matrix out(?,1:4) appear in matrix p. for for row one in matrix out, 1,2,3 and 4 in any combination appear 4 time in the rows of matrix p.
      So more examples...
      p = [1 2 3 4 9;
           2 3 1 4 8]
      v = 4;
      out =
           1     2     3     4     2
    %so any combination of 1,2,3 and 4 appear 2 times in matrix p
    and another:
    p = [1 2 3 4 9;
         2 3 1 4 8;
         3 4 2 7 1]
    v = 3;
    out =
         1     2     3     3
         1     2     4     3
         1     3     4     3
         2     3     4     3
    %so this uses any combo of 3 values, so in this case out(?,1:3) are the number combos that can be found in matrix p, and the out(?,4) is the amount of times that those combos are found
    last example:
    p = [1 2 3 4 9;
         2 3 1 4 8]
    v = 2;
    out =
         1     2     2
         1     3     2
         1     4     2
         2     3     2
         2     4     2
         3     4     2
    %so in this case only combos of out(?,1:2) are found and out(?,3) is the amounts of times that combo of out(?,1:2) is found in matrix p. so row four of matrix out (so out(4,:)...) shows that the combo of 2 and 3 are found 2 times in matrix p.

NOTE: only display any row number combos that occur at least 2 times or more!

I hope I gave enough instructions and explanation, if not please let me know and I will add to it! Thanks and good luck!

Solution Stats

56.52% Correct | 43.48% Incorrect
Last Solution submitted on Oct 07, 2023

Solution Comments

Show comments

Problem Recent Solvers10

Suggested Problems

More from this Author17

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!