0

I have this 2d array called input and I am trying to map different numbers in another array to change it. In the 2d array mapping it contains all the mappings I want to perform.The first array is {0,2,3,4,1,5} and I want to use this to change the values in input so every 1 becomes a 2, and 2 to 3 and 3 to 4 and 4 to 1. I have 23 different mappings in that mapping array which I would want to change the values of input. Here is what I have tried so far.

 public static int [][] mapOrientation(int input[][]){
    int [][] input = {{0,0,0,5},{4,1,1,4},{2,2,0,2},{1,2,3,5},{3,3,3,4},{1,5,5,4}};

     int[][] mapping ={{0,2,3,4,1,5},{1,2,0,4,5,3},{5,2,1,4,3,0},{3,2,5,4,0,1},
                       {3,5,4,0,2,1},{2,5,3,0,1,4},{1,5,2,0,4,3},{4,5,1,0,3,2},
                       {4,1,0,3,5,2},{5,1,4,3,2,0},{2,1,5,3,0,4},{0,1,2,3,4,5},
                       {0,4,1,2,3,5},{3,4,0,2,5,1},{5,4,3,2,1,0},{1,4,5,2,0,3},
                       {1,0,4,5,2,3},{2,0,1,5,3,4},{3,0,2,5,4,1},{4,0,3,5,1,2},
                       {4,1,0,3,5,2},{5,1,4,3,2,0},{2,1,5,3,0,4}};

    int [] comb = mapping[0];
    for(int i = 0; i < input.length; i++){
        for(int j = 0; j < input[i].length; j++){

            input[i][j] = comb[0];
            System.out.println(comb[0]);
            System.out.println(Arrays.deepToString(input));

   cubeToString = Arrays.deepToString(input);

    return input;
}

If this is still unclear my goal is to change input from

int [][] input ={{5,1,2,0},{2,0,1,4},{1,2,5,5},{3,0,1,3},{4,3,0,4},{3,2,5,4}} 

to:

int [][] input ={{5,2,3,0},{3,0,2,1},{2,3,5,5},{4,0,2,4},{1,4,0,1},{4,3,5,1}}

This would be the result I want using comb[0].

14
  • why are the mapping arrays bigger than the input arrays? i'm confused... is the result you want based on using the mapping[0][0] on input and the result would be in comb[0]? Commented Jan 11, 2017 at 17:14
  • because the mapping arrays contain the combination of mappings of which I would like to use to modify input so I use comb[0] to access the first mapping array @RAZ_Muh_Taz Commented Jan 11, 2017 at 17:17
  • What do you mean by the mapping arrays contain the combination of mappings? how does it work ? Commented Jan 11, 2017 at 17:19
  • No 0 -> 0, 1-> 2, 2 -> 3, 3 -> 4, 4 -> 1 is the first combination. @Michael Commented Jan 11, 2017 at 17:22
  • Is the number of inputs aqual to the number of the mappings or you just want to implement one mapping to all the inputs? Commented Jan 11, 2017 at 17:22

1 Answer 1

1

Your problem is with this line:

 input[i][j] = comb[0];

You are setting the value to always equal the first item of the mapping. What you actually want is

 input[i][j] = comb[input[i][j]];

Runnable example

public class NewClass
{
    public static void main(String... args)
    {
        int[][] input = {{5,1,2,0},{2,0,1,4},{1,2,5,5},{3,0,1,3},{4,3,0,4},{3,2,5,4}};
        mapOrientation(input);
    }

    public static int [][] mapOrientation(int input[][])
    {
        int[][] mappings ={{0,2,3,4,1,5},{1,2,0,4,5,3},{5,2,1,4,3,0},{3,2,5,4,0,1},
                           {3,5,4,0,2,1},{2,5,3,0,1,4},{1,5,2,0,4,3},{4,5,1,0,3,2},
                           {4,1,0,3,5,2},{5,1,4,3,2,0},{2,1,5,3,0,4},{0,1,2,3,4,5},
                           {0,4,1,2,3,5},{3,4,0,2,5,1},{5,4,3,2,1,0},{1,4,5,2,0,3},
                           {1,0,4,5,2,3},{2,0,1,5,3,4},{3,0,2,5,4,1},{4,0,3,5,1,2},
                           {4,1,0,3,5,2},{5,1,4,3,2,0},{2,1,5,3,0,4}};

        System.out.println("Before");
        System.out.println(Arrays.deepToString(input));

        int[] mapping = mappings[0];
        for(int i = 0; i < input.length; i++)
        {
            for(int j = 0; j < input[i].length; j++)
            {
                input[i][j] = mapping[input[i][j]];
            }
        }

        System.out.println("After");
        System.out.println(Arrays.deepToString(input));

        //cubeToString = Arrays.deepToString(input);

        return input;
    }
}
Sign up to request clarification or add additional context in comments.

2 Comments

I did try doing that as well but it wouldn't change the values of input.
I've tested it and it matches your expected results. I've edited in a runnable example to my answer.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.