# How can I compute the permutations multiplication "like" table to a linear list?

I have a table that is structured like this. I would like to transform the table into the permutations of the table if we treated like a multiplication table. Into a list that looks like this. Please note I am using a multiplication table as an example. The actual data I am parsing is random. The reason I choose to use a multiplication table data is the lookup method for my table data is performed by the same method. e.g where you check where two different inputs on the x-axes and y-axes and where they converge gives you the value.

• You want to convert the values of above image to the values of below image.

If my understanding is correct and you use Google Apps Script, how about this sample script? I think that there are several solutions for your situation. So please think of this as just one of them.

• In this sample script, it supposes that the initial values are put to the cells of "A1:D4" in the active sheet. And the result is put to the cells of "A6:C23".
• The point of this sample script is that all patterns are retrieved by transposing the values.

### Sample script:

``````var sheet = SpreadsheetApp.getActiveSheet();
var values = sheet.getRange("A1:D4").getValues(); // Retrieve the initial values

var ar = [];
for (var loop = 1; loop >= 0; loop--) {
var temp = [];
for (var i = 1; i < values.length; i++) {
for (var j = 1; j < values[i].length; j++) {
temp.push([values[j], values[i], values[i][j]]);
}
}
ar[loop] = temp;
values = values.map(function(_, i) {return values.map(function(f, j) {return f[i]})}); // Transpose the initial values.
}
var res = Array.prototype.concat.apply([], ar);

sheet.getRange("A6:C23").setValues(res); // Put the result
``````

### Result: • "A1:D4" is the initial values.
• "A6:C23" is the result values.

### Note:

• This is a simple sample script. So please modify it for your situation.

If I misunderstood your question, I apologize.

• @user136952 I'm glad your issue was resolved. Thank you, too. Mar 9 '19 at 1:17