解法は知りませんが根幹となりませんか?
応用の仕方の例も掲載し、ちょっと手直ししました。
HTML&JS
1<!DOCTYPE html>
2<meta charset="UTF-8">
3<title>A23</title>
4<style>
5td, input[type="button"] {
6 font-size: xx-large;
7 border: 2px gray ridge;
8 border-radius: 40px;
9 padding: 1ex 1em;
10}
11</style>
12
13<body>
14<table id="A">
15 <tr><td><td><td>
16 <tr><td><td><td>
17</table>
18<p>
19 <input type="button" value="L">
20 <input type="button" value="Reset">
21 <input type="button" value="R"><br>
22 <input type="text" size="40" value="" id="S">
23</p>
24
25<script>
26class A23 {
27 constructor (...arg) {
28 this.reset (...arg);
29 }
30
31 R () {
32 let [a,b,c,d,e,f] = this.map;
33 this.map = [a,e,b,d,f,c];
34 this.history += 'R';
35 return this;
36 }
37
38 L () {
39 let [a,b,c,d,e,f] = this.map;
40 this.map = [b,e,c,a,d,f];
41 this.history += 'L';
42 return this;
43 }
44
45 advance (str ='') {
46 [...str].forEach (s=> this[s]());
47 this.history += str;
48 return this;
49 }
50
51 reset (LR = '', map = [0, 1, 2, 3, 4, 5]) {
52 this.map = map;
53 this.history = '';
54 return this.advance (LR);
55 }
56
57 copy () {
58 return new this.constructor ('', this.map);
59 }
60}
61
62//____________________________
63
64function disp () {
65 [...A.querySelectorAll ('td')]
66 .forEach ((e, i)=> e.textContent = a23.map[i]);
67 S.value = a23.history;
68}
69
70function handler ({target: e}) {
71 let { type, value } = e;
72 if ('button' === type)
73 switch (e.value) {
74 case 'L' : a23.L (); break;
75 case 'R' : a23.R (); break;
76 case 'Reset': a23.reset ();
77 }
78 disp ();
79}
80
81const a23 = new A23;
82disp ();
83document.addEventListener ('click', handler, false);
84
85
86</script>