PageSourceSearch

https://blddb.net/assets/js/commutator.js

js blddb.net collected 2026-10-06 13:14:40 UTC 29,514 bytes, 803 lines download raw bytes

1var MAX_INT = 4294967295;
2var orderInit = 4, outerBracketInit = false, abMaxScoreInit = 2.5, abMinScoreInit = 5, addScoreInit = 1, maxDepthInit = 1, limitInit = 0, fastInit = false;
3var commuteInit = {
4    U: { "class": 1, priority: 1 },
5    u: { "class": 1, priority: 2 },
6    E: { "class": 1, priority: 3 },
7    D: { "class": 1, priority: 4 },
8    d: { "class": 1, priority: 5 },
9    R: { "class": 2, priority: 1 },
10    r: { "class": 2, priority: 2 },
11    M: { "class": 2, priority: 3 },
12    L: { "class": 2, priority: 4 },
13    l: { "class": 2, priority: 5 },
14    F: { "class": 3, priority: 1 },
15    f: { "class": 3, priority: 2 },
16    S: { "class": 3, priority: 3 },
17    B: { "class": 3, priority: 4 },
18    b: { "class": 3, priority: 5 }
19};
20var initialReplaceInit = {
21    r2: "R2 M2",
22    "r'": "R' M",
23    r: "R M'",
24    l2: "M2 L2",
25    "l'": "M' L'",
26    l: "M L",
27    f2: "F2 S2",
28    "f'": "F' S'",
29    f: "F S",
30    b2: "S2 B2",
31    "b'": "S B'",
32    b: "S' B",
33    u2: "U2 E2",
34    "u'": "U' E",
35    u: "U E'",
36    d2: "E2 D2",
37    "d'": "E' D'",
38    d: "E D"
39};
40var finalReplaceInit = {
41    "R2 M2": "r2",
42    "R' M": "r'",
43    "R M'": "r",
44    "M2 L2": "l2",
45    "M' L'": "l'",
46    "M L": "l",
47    "F2 S2": "f2",
48    "F' S'": "f'",
49    "F S": "f",
50    "S2 B2": "b2",
51    "S B'": "b'",
52    "S' B": "b",
53    "U2 E2": "u2",
54    "U' E": "u'",
55    "U E'": "u",
56    "E2 D2": "d2",
57    "E' D'": "d'",
58    "E D": "d",
59    "M2 R2": "r2",
60    "M R'": "r'",
61    "M' R": "r",
62    "L2 M2": "l2",
63    "L' M'": "l'",
64    "L M": "l",
65    "S2 F2": "f2",
66    "S' F'": "f'",
67    "S F": "f",
68    "B2 S2": "b2",
69    "B' S": "b'",
70    "B S'": "b",
71    "E2 U2": "u2",
72    "E U'": "u'",
73    "E' U": "u",
74    "D2 E2": "d2",
75    "D' E'": "d'",
76    "D E": "d",
77    "R M2": "r M'",
78    "R' M2": "r' M",
79    "M2 R": "r M'",
80    "M2 R'": "r' M",
81    "U2 E": "U' u'",
82    "U2 E'": "U u",
83    "E U2": "U' u'",
84    "E' U2": "U u",
85    "U E2": "U' u2",
86    "U' E2": "U u2",
87    "E2 U": "U' u2",
88    "E2 U'": "U u2"
89};
90var result = [], order = orderInit, minAmount = Math.floor(orderInit / 2) + 1 - orderInit, maxAmount = Math.floor(orderInit / 2), maxAlgAmount = 0, isOrderZero = false, outerBracket = outerBracketInit, abMaxScore = abMaxScoreInit, abMinScore = abMinScoreInit, addScore = addScoreInit, fast = false;
91var commute = commuteInit, initialReplace = initialReplaceInit, finalReplace = finalReplaceInit;
92function expandOrigin(input) {
93    var _a, _b, _c, _d;
94    var algorithm = input.algorithm;
95    order = (_a = input.order) !== null && _a !== void 0 ? _a : orderInit;
96    initialReplace = (_b = input.initialReplace) !== null && _b !== void 0 ? _b : initialReplaceInit;
97    finalReplace = (_c = input.finalReplace) !== null && _c !== void 0 ? _c : finalReplaceInit;
98    commute = (_d = input.commute) !== null && _d !== void 0 ? _d : commuteInit;
99    algorithm = algorithm.replace(/[‘]/gu, "'");
100    algorithm = algorithm.replace(/[’]/gu, "'");
101    algorithm = algorithm.replace(/\(/gu, "");
102    algorithm = algorithm.replace(/\)/gu, "");
103    algorithm = algorithm.replace(/(/gu, "");
104    algorithm = algorithm.replace(/)/gu, "");
105    algorithm = algorithm.replace(/\{/gu, "");
106    algorithm = algorithm.replace(/\}/gu, "");
107    algorithm = algorithm.replace(/\s/gu, "");
108    algorithm = algorithm.split("").join(" ");
109    algorithm = algorithm.replace(/【/gu, "[");
110    algorithm = algorithm.replace(/】/gu, "]");
111    algorithm = algorithm.replace(/:/gu, ":");
112    algorithm = algorithm.replace(/,/gu, ",");
113    algorithm = algorithm.replace(/: /gu, ":");
114    algorithm = algorithm.replace(/, /gu, ",");
115    algorithm = algorithm.replace(/\[ /gu, "[");
116    algorithm = algorithm.replace(/\] /gu, "]");
117    algorithm = algorithm.replace(/ :/gu, ":");
118    algorithm = algorithm.replace(/ ,/gu, ",");
119    algorithm = algorithm.replace(/ \[/gu, "[");
120    algorithm = algorithm.replace(/ \]/gu, "]");
121    algorithm = "[".concat(algorithm.replace(/\+/gu, "]+["), "]");
122    algorithm = algorithm.replace(/\]\[/gu, "]+[");
123    if (order === 0) {
124        isOrderZero = true;
125        order = MAX_INT;
126    }
127    else {
128        isOrderZero = false;
129    }
130    // Examples:
131    // • order 4 → min -1 (e.g. cube)
132    // • order 5 → min -2 (e.g. Megaminx)
133    // • order 3 → min -1 (e.g. Pyraminx)
134    minAmount = Math.floor(order / 2) + 1 - order;
135    maxAmount = Math.floor(order / 2);
136    var rpnStack = rpn(initStack(algorithm));
137    if (rpnStack[0] === "Lack left parenthesis." ||
138        rpnStack[0] === "Lack right parenthesis.") {
139        return rpnStack[0];
140    }
141    var calcTemp = calc(rpnStack);
142    if (calcTemp === "") {
143        return "";
144    }
145    var expandOutput = arrayToStr(algToArray(calcTemp));
146    if (expandOutput === "") {
147        return "";
148    }
149    return expandOutput;
150}
151function isOperator(sign) {
152    var operatorString = "+:,/[]";
153    return operatorString.indexOf(sign) > -1;
154}
155function initStack(algorithm) {
156    var stack = [algorithm[0]];
157    for (var i = 1; i < algorithm.length; i++) {
158        if (isOperator(algorithm[i]) || isOperator(stack.slice(-1)[0])) {
159            stack.push(algorithm[i]);
160        }
161        else {
162            stack.push(stack.pop() + algorithm[i]);
163        }
164    }
165    return stack;
166}
167function operatorLevel(operator) {
168    if (operator === ":") {
169        return 0;
170    }
171    if (operator === ",") {
172        return 1;
173    }
174    if (operator === "/") {
175        return 2;
176    }
177    if (operator === "+") {
178        return 3;
179    }
180    if (operator === "[") {
181        return 4;
182    }
183    if (operator === "]") {
184        return 5;
185    }
186    return -1;
187}
188function rpn(stackInput) {
189    // Reverse Polish Notation
190    var stackOutput = [], operatorStack = [];
191    var isMatch = false, operatorStackPop = "";
192    while (stackInput.length > 0) {
193        var sign = stackInput.shift();
194        if (!isOperator(sign)) {
195            stackOutput.push(sign);
196        }
197        else if (sign === "]") {
198            isMatch = false;
199            while (operatorStack.length > 0) {
200                operatorStackPop = operatorStack.pop();
201                if (operatorStackPop === "[") {
202                    isMatch = true;
203                    break;
204                }
205                else {
206                    stackOutput.push(operatorStackPop);
207                }
208            }
209            if (!isMatch) {
210                return ["Lack left parenthesis."];
211            }
212        }
213        else {
214            while (operatorStack.length > 0 &&
215                operatorStack.slice(-1)[0] !== "[" &&
216                operatorLevel(sign) <= operatorLevel(operatorStack.slice(-1)[0])) {
217                stackOutput.push(operatorStack.pop());
218            }
219            operatorStack.push(sign);
220        }
221    }
222    while (operatorStack.length > 0) {
223        operatorStackPop = operatorStack.pop();
224        if (operatorStackPop === "[") {
225            return ["Lack right parenthesis."];
226        }
227        stackOutput.push(operatorStackPop);
228    }
229    return stackOutput;
230}
231function calc(stack) {
232    var _a;
233    var calcOutput = [];
234    while (stack.length > 0) {
235        var sign = stack.shift();
236        if (isOperator(sign)) {
237            if (calcOutput.length >= 2) {
238                var calcPop2 = calcOutput.pop();
239                var calcPop1 = calcOutput.pop();
240                calcOutput.push(calcTwo(calcPop1, calcPop2, sign));
241            }
242            else {
243                return "";
244            }
245        }
246        else {
247            calcOutput.push(sign);
248        }
249    }
250    return (_a = calcOutput[0]) !== null && _a !== void 0 ? _a : "";
251}
252function calcTwo(algorithm1, algorithm2, sign) {
253    var array1 = [], array2 = [];
254    array1 = algToArray(algorithm1);
255    array2 = algToArray(algorithm2);
256    switch (sign) {
257        case "+":
258            return arrayToStr(array1.concat(array2));
259        case ":":
260            return arrayToStr(array1.concat(array2, invert(array1)));
261        case ",":
262            return arrayToStr(array1.concat(array2, invert(array1), invert(array2)));
263        case "/":
264            return arrayToStr(array1.concat(array2, invert(array1), invert(array1), invert(array2), array1));
265        default:
266            return arrayToStr(array1.concat(array2));
267    }
268}
269function score(algorithm) {
270    var alg = algorithm;
271    alg = "[".concat(alg.replace(/\+/gu, "]+["), "]");
272    alg = alg.replace(/\]\[/gu, "]+[");
273    var rpnStack = rpn(initStack(alg)), scoreOutput = [];
274    while (rpnStack.length > 0) {
275        var sign = rpnStack.shift();
276        if (isOperator(sign)) {
277            var scorePop2 = scoreOutput.pop();
278            var scorePop1 = scoreOutput.pop();
279            var score1 = Number(scorePop1), score2 = Number(scorePop2);
280            if (isNaN(score1)) {
281                score1 = scorePop1.split(" ").length;
282            }
283            if (isNaN(score2)) {
284                score2 = scorePop2.split(" ").length;
285            }
286            scoreOutput.push(scoreTwo(score1, score2, sign).toString());
287        }
288        else {
289            scoreOutput.push(sign);
290        }
291    }
292    return Number(scoreOutput[0]);
293}
294function scoreTwo(score1, score2, sign) {
295    switch (sign) {
296        case "+":
297            return score1 + score2 + addScore;
298        case ":":
299            return score1 + score2;
300        case ",":
301            return (abMaxScore * Math.max(score1, score2) +
302                abMinScore * Math.min(score1, score2));
303        default:
304            return Infinity;
305    }
306}
307function sortRule(algorithm1, algorithm2) {
308    return score(algorithm1) - score(algorithm2);
309}
310function search(input) {
311    var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l;
312    var algorithm = input.algorithm;
313    order = (_a = input.order) !== null && _a !== void 0 ? _a : orderInit;
314    outerBracket = (_b = input.outerBracket) !== null && _b !== void 0 ? _b : outerBracketInit;
315    abMaxScore = (_c = input.abMaxScore) !== null && _c !== void 0 ? _c : abMaxScoreInit;
316    abMinScore = (_d = input.abMinScore) !== null && _d !== void 0 ? _d : abMinScoreInit;
317    addScore = (_e = input.addScore) !== null && _e !== void 0 ? _e : addScoreInit;
318    initialReplace = (_f = input.initialReplace) !== null && _f !== void 0 ? _f : initialReplaceInit;
319    finalReplace = (_g = input.finalReplace) !== null && _g !== void 0 ? _g : finalReplaceInit;
320    commute = (_h = input.commute) !== null && _h !== void 0 ? _h : commuteInit;
321    fast = (_j = input.fast) !== null && _j !== void 0 ? _j : fastInit;
322    var maxDepth = (_k = input.maxDepth) !== null && _k !== void 0 ? _k : maxDepthInit, limit = (_l = input.limit) !== null && _l !== void 0 ? _l : limitInit;
323    result = [];
324    if (algorithm === "") {
325        return [""];
326    }
327    var arr = algToArray(algorithm);
328    if (order === 0) {
329        isOrderZero = true;
330        order = 2 * (maxAlgAmount + 2);
331    }
332    else {
333        isOrderZero = false;
334    }
335    // Examples:
336    // • order 4 → min -1 (e.g. cube)
337    // • order 5 → min -2 (e.g. Megaminx)
338    // • order 3 → min -1 (e.g. Pyraminx)
339    minAmount = Math.floor(order / 2) + 1 - order;
340    maxAmount = Math.floor(order / 2);
341    arr = simplify(arr);
342    var arrLen = arr.length;
343    if (arrLen === 0) {
344        return [""];
345    }
346    for (var i = 0; i < arrLen; i++) {
347        var amountCount = 0;
348        for (var j = 0; j < arrLen; j++) {
349            if (arr[i].base === arr[j].base) {
350                amountCount = amountCount + arr[j].amount;
351            }
352        }
353        if (amountCount % order !== 0) {
354            return ["Not found."];
355        }
356    }
357    var commuteCount = 0;
358    var commuteIndex = [];
359    for (var i = 0; i < arrLen - 1; i++) {
360        if (isSameClass(arr[i], arr[i + 1])) {
361            commuteIndex[commuteCount] = i;
362            commuteCount += 1;
363        }
364    }
365    var commuteTotal = Math.pow(2, commuteCount);
366    var commutatorOutput = ["Not found."], isFind = false;
367    var searchDepth = 0;
368    if (maxDepth === 0) {
369        searchDepth = Math.floor((arrLen - 1) / 3);
370    }
371    else {
372        searchDepth = maxDepth;
373    }
374    for (var depth = 1; depth <= searchDepth; depth++) {
375        for (var i = 0; i < commuteTotal; i++) {
376            var commutBinary = String(i.toString(2));
377            var commuteArr = arr.concat();
378            for (var j = 0; j < commutBinary.length; j++) {
379                if (commutBinary[commutBinary.length - 1 - j] === "1") {
380                    commuteArr = swapArray(commuteArr, commuteIndex[j], commuteIndex[j] + 1);
381                }
382            }
383            commutatorOutput = commutatorMain(commuteArr, depth, depth);
384            if (commutatorOutput[0] !== "Not found.") {
385                isFind = true;
386            }
387            if (fast && isFind) {
388                return result;
389            }
390        }
391        if (isFind && (depth === maxDepth || maxDepth === 0)) {
392            result.sort(sortRule);
393            if (limit === 0) {
394                return result;
395            }
396            return result.slice(0, limit);
397        }
398    }
399    return ["Not found."];
400}
401function algToArray(algorithm) {
402    var algTemp = algorithm;
403    algTemp = algTemp.replace(/\s+/giu, "");
404    algTemp = algTemp.replace(/[‘]/gu, "'");
405    algTemp = algTemp.replace(/[’]/gu, "'");
406    if (algTemp === "") {
407        return [];
408    }
409    if (Object.keys(initialReplace).length > 0) {
410        algTemp = algTemp.replace(/[A-Z]w/gu, function (match) {
411            return match.charAt(0).toLowerCase();
412        });
413    }
414    var alg = "";
415    for (var i = 0; i < algTemp.length; i++) {
416        if ((algTemp[i + 1] < "0" || algTemp[i + 1] > "9") &&
417            algTemp[i + 1] !== "'") {
418            alg = "".concat(alg + algTemp[i], " ");
419        }
420        else {
421            alg = alg + algTemp[i];
422        }
423    }
424    for (var i in initialReplace) {
425        var re = new RegExp(i, "gu");
426        var testStr = initialReplace[i].replace(/[^a-zA-Z]/gu, "").split("");
427        for (var _i = 0, testStr_1 = testStr; _i < testStr_1.length; _i++) {
428            var testChar = testStr_1[_i];
429            if (alg.indexOf(testChar) > -1) {
430                alg = alg.replace(re, initialReplace[i]);
431            }
432        }
433    }
434    var algSplit = alg.split(" ");
435    var arr = [];
436    for (var i = 0; i < algSplit.length; i++) {
437        arr[i] = { base: algSplit[i][0], amount: 0 };
438        var algNumber = algSplit[i].replace(/[^0-9]/gu, "");
439        if (algNumber === "") {
440            arr[i].amount = 1;
441        }
442        else {
443            arr[i].amount = Number(algNumber);
444        }
445        if (arr[i].amount > maxAlgAmount) {
446            maxAlgAmount = arr[i].amount;
447        }
448        if (algSplit[i].indexOf("'") > -1) {
449            arr[i].amount = -arr[i].amount;
450        }
451    }
452    return arr;
453}
454function commutatorPre(array, depth, maxSubDepth) {
455    var commuteCount = 0;
456    var commuteIndex = [];
457    for (var i = 0; i < array.length - 1; i++) {
458        if (isSameClass(array[i], array[i + 1])) {
459            commuteIndex[commuteCount] = i;
460            commuteCount += 1;
461        }
462    }
463    var commuteTotal = Math.pow(2, commuteCount);
464    var commutatorResult = ["Not found."];
465    for (var i = 0; i < commuteTotal; i++) {
466        var commutBinary = String(i.toString(2));
467        var commuteArr = array.concat();
468        for (var j = 0; j < commutBinary.length; j++) {
469            if (commutBinary[commutBinary.length - 1 - j] === "1") {
470                commuteArr = swapArray(commuteArr, commuteIndex[j], commuteIndex[j] + 1);
471            }
472        }
473        commutatorResult = commutatorMain(commuteArr, depth, maxSubDepth);
474        if (commutatorResult[0] !== "Not found.") {
475            return commutatorResult;
476        }
477    }
478    return ["Not found."];
479}
480function commutatorMain(array, depth, maxSubDepth) {
481    var arr = simplify(array), commutatorOutput = "";
482    var arrBak = arr.concat(), arrLen = arr.length;
483    if (arr.length < 3 * depth + 1) {
484        return ["Not found."];
485    }
486    for (var d = 0; d <= (arrLen + arr.length + 1) / 2 - 1; d++) {
487        for (var drKey = 1; drKey < order; drKey++) {
488            // 1, -1, 2, -2...
489            var dr = ((drKey % 2) * 2 - 1) * Math.floor((drKey + 1) / 2);
490            if (d === 0) {
491                if (drKey > 1) {
492                    break;
493                }
494            }
495            else {
496                if (Math.abs(dr) > Math.abs(arrBak[d - 1].amount)) {
497                    break;
498                }
499                if (order % 2 === 1 ||
500                    arrBak[d - 1].amount !== Math.floor(order / 2)) {
501                    if ((arrBak[d - 1].amount < 0 && dr > 0) ||
502                        (arrBak[d - 1].amount > 0 && dr < 0)) {
503                        continue;
504                    }
505                }
506            }
507            arr = displace(arrBak, d, dr);
508            // For a b c b' a' d c' d' = a b:[c,b' a' d]
509            for (var i = 1; i <= arr.length / 2 - 1; i++) {
510                var minj = 0;
511                if (depth === 1) {
512                    minj = Math.max(1, Math.ceil(arr.length / 2 - i));
513                }
514                else {
515                    minj = 1;
516                }
517                for (var j = minj; j <= arr.length / 2 - 1; j++) {
518                    var part1x = [], part2x = [];
519                    var commuteAdd1 = [[]], commuteAdd2 = [[]];
520                    if (arr[i - 1].base === arr[i + j - 1].base) {
521                        // For [a bx,by c bz]
522                        for (var ir = minAmount; ir <= maxAmount; ir++) {
523                            if (ir === 0) {
524                                continue;
525                            }
526                            var jr = normalize(arr[i + j - 1].amount + ir);
527                            part1x = simplify(repeatEnd(arr.slice(0, i), ir));
528                            commuteAdd1.push(part1x);
529                            part2x = simplify(invert(part1x).concat(repeatEnd(arr.slice(0, i + j), jr)));
530                            commuteAdd2.push(part2x);
531                        }
532                    }
533                    else {
534                        if (depth === 1 && arr[i].base !== arr[arr.length - 1].base) {
535                            continue;
536                        }
537                        part1x = simplify(arr.slice(0, i));
538                        commuteAdd1.push(part1x);
539                        part2x = simplify(arr.slice(i, i + j));
540                        commuteAdd2.push(part2x);
541                        var commuteCase = [];
542                        if (isSameClass(arr[i - 1], arr[i + j - 1])) {
543                            // For L a R b L' a' R' b' = [L a R,b L' R]
544                            commuteAdd1.push(part1x);
545                            commuteCase = simplify(part2x.concat([arr[i - 1]]));
546                            commuteAdd2.push(commuteCase);
547                            // For L a R L b R L2' a' R2' b' = [L a R L,b R2 L']
548                            if (i >= 2) {
549                                if (isSameClass(arr[i - 1], arr[i - 2])) {
550                                    commuteAdd1.push(part1x);
551                                    commuteCase = simplify(part2x.concat(arr.slice(i - 2, i)));
552                                    commuteAdd2.push(commuteCase);
553                                }
554                            }
555                        }
556                        if (isSameClass(arr[i], arr[i + j])) {
557                            // For a R b L a' R' b' L' = [a R b R,R' L a'] = [a R L',L b R]
558                            commuteCase = simplify(part1x.concat(invert([arr[i + j]])));
559                            commuteAdd1.push(commuteCase);
560                            commuteCase = simplify([arr[i + j]].concat(part2x));
561                            commuteAdd2.push(commuteCase);
562                            // For a R2 b R' L2 a' R' L' b' L' = [a R2 b L R,R2' L a'] = [a R2 L',L b R L]
563                            if (arr.length >= i + j + 2) {
564                                if (isSameClass(arr[i + j], arr[i + j + 1])) {
565                                    commuteCase = simplify(part1x.concat(invert(arr.slice(i + j, i + j + 2))));
566                                    commuteAdd1.push(commuteCase);
567                                    commuteCase = simplify(arr.slice(i + j, i + j + 2).concat(part2x));
568                                    commuteAdd2.push(commuteCase);
569                                }
570                            }
571                        }
572                    }
573                    for (var commuteAddKey = 1; commuteAddKey < commuteAdd1.length; commuteAddKey++) {
574                        part1x = commuteAdd1[commuteAddKey];
575                        part2x = commuteAdd2[commuteAddKey];
576                        var subArr = simplify(part2x.concat(part1x, invert(part2x), invert(part1x), arr));
577                        var subPart = "";
578                        if (depth > 1) {
579                            subPart = commutatorPre(subArr, depth - 1, maxSubDepth)[0];
580                        }
581                        else if (subArr.length > 0) {
582                            continue;
583                        }
584                        if (subPart !== "Not found.") {
585                            var part1y = part1x, part2y = part2x;
586                            var party = simplify(part2x.concat(part1x));
587                            if (party.length < Math.max(part1x.length, part2x.length)) {
588                                if (part1x.length <= part2x.length) {
589                                    // For a b c d e b' a' c' e' d' = [a b c,d e b' a'] = [a b c,d e c]
590                                    part1y = part1x;
591                                    part2y = party;
592                                }
593                                else {
594                                    // For a b c d e b' a' d' c' e' = [a b c,d e b' a'] = [a b c d,e b' a']
595                                    part1y = invert(part2x);
596                                    part2y = party;
597                                }
598                            }
599                            // For a b c b' a' d c' d' = a b:[c,b' a' d] = d:[d' a b,c]
600                            var part0 = simplify(repeatEnd(arrBak.slice(0, d), dr)), part1 = part1y, part2 = part2y;
601                            if (part0.length > 0 && maxSubDepth === 1) {
602                                var partz = simplify(part0.concat(part2y));
603                                // Avoid a b c b' a' d c' d' = d:[d' a b,c], use a b:[c,b' a' d] instead.
604                                if (partz.length < part0.length - 1) {
605                                    part0 = partz;
606                                    part1 = invert(part2y);
607                                    part2 = part1y;
608                                }
609                            }
610                            var part1Output = arrayToStr(part1), part2Output = arrayToStr(part2), part0Output = arrayToStr(part0);
611                            if (part1Output === "" || part2Output === "") {
612                                continue;
613                            }
614                            var commutatorStr = pairToStr(part0Output, part1Output, part2Output, subPart);
615                            if (commutatorOutput === "") {
616                                commutatorOutput = commutatorStr;
617                            }
618                            if (score(commutatorStr) < score(commutatorOutput)) {
619                                commutatorOutput = commutatorStr;
620                            }
621                            if (depth === maxSubDepth &&
622                                result.indexOf(commutatorStr) === -1) {
623                                result.push(commutatorStr);
624                            }
625                            if (fast) {
626                                return [commutatorOutput];
627                            }
628                        }
629                    }
630                }
631            }
632        }
633    }
634    if (commutatorOutput === "") {
635        return ["Not found."];
636    }
637    return [commutatorOutput];
638}
639function repeatEnd(array, attempt) {
640    var arr = array.concat();
641    if (arr.length === 0) {
642        return [];
643    }
644    var arrPop = arr.pop();
645    if (attempt === 0) {
646        return arr;
647    }
648    arr.push({ base: arrPop.base, amount: attempt });
649    return arr;
650}
651function pairToStr(part0, part1, part2, subPart) {
652    if (subPart === "") {
653        if (!outerBracket) {
654            if (part0 === "") {
655                return "[".concat(part1, ",").concat(part2, "]");
656            }
657            return "".concat(part0, ":[").concat(part1, ",").concat(part2, "]");
658        }
659        else if (part0 === "") {
660            return "[".concat(part1, ",").concat(part2, "]");
661        }
662        return "[".concat(part0, ":[").concat(part1, ",").concat(part2, "]]");
663    }
664    if (!outerBracket) {
665        if (part0 === "") {
666            return "[".concat(part1, ",").concat(part2, "]+").concat(subPart);
667        }
668        return "".concat(part0, ":[[").concat(part1, ",").concat(part2, "]+").concat(subPart, "]");
669    }
670    else if (part0 === "") {
671        return "[".concat(part1, ",").concat(part2, "]").concat(subPart);
672    }
673    return "[".concat(part0, ":[").concat(part1, ",").concat(part2, "]").concat(subPart, "]");
674}
675function displace(array, d, dr) {
676    var arr = array.concat(), arrEnd = repeatEnd(arr.slice(0, d), dr);
677    return simplify(invert(arrEnd).concat(arr, arrEnd));
678}
679function invert(array) {
680    var arr = [];
681    for (var i = array.length - 1; i >= 0; i--) {
682        arr.push({ base: array[i].base, amount: normalize(-array[i].amount) });
683    }
684    return arr;
685}
686function arrayToStr(array) {
687    var arr = array.concat();
688    arr = simplify(arr);
689    if (arr.length === 0) {
690        return "";
691    }
692    for (var times = 0; times <= 1; times++) {
693        for (var i = 0; i < arr.length - 1; i++) {
694            if (isSameClass(arr[i], arr[i + 1]) &&
695                commute[arr[i].base].priority > commute[arr[i + 1].base].priority) {
696                arr = swapArray(arr, i, i + 1);
697            }
698        }
699    }
700    var arrTemp = [];
701    for (var i = 0; i < arr.length; i++) {
702        if (arr[i].amount < 0) {
703            if (arr[i].amount === -1) {
704                arrTemp[i] = "".concat(arr[i].base, "'");
705            }
706            else {
707                arrTemp[i] = "".concat(arr[i].base + -arr[i].amount, "'");
708            }
709        }
710        else if (arr[i].amount === 1) {
711            arrTemp[i] = arr[i].base;
712        }
713        else {
714            arrTemp[i] = arr[i].base + arr[i].amount;
715        }
716    }
717    var arrOutput = "".concat(arrTemp.join(" "), " ");
718    for (var i in finalReplace) {
719        var re = new RegExp("".concat(i, " "), "gu");
720        arrOutput = arrOutput.replace(re, "".concat(finalReplace[i], " "));
721    }
722    arrOutput = arrOutput.substring(0, arrOutput.length - 1);
723    return arrOutput;
724}
725function simplify(array) {
726    if (array.length === 0) {
727        return [];
728    }
729    var arr = [];
730    for (var i = 0; i < array.length; i++) {
731        var arrayAdd = {
732            base: array[i].base,
733            amount: normalize(array[i].amount)
734        }, arrLen = arr.length;
735        if (normalize(arrayAdd.amount) === 0) {
736            continue;
737        }
738        var isChange = false;
739        for (var j = 1; j <= 3; j++) {
740            if (arr.length >= j) {
741                if (arr[arrLen - j].base === arrayAdd.base) {
742                    var canCommute = true;
743                    if (j >= 2) {
744                        for (var k = 1; k <= j; k++) {
745                            if (!(arr[arrLen - k].base in commute)) {
746                                canCommute = false;
747                                break;
748                            }
749                        }
750                        for (var k = 2; k <= j; k++) {
751                            if (!isSameClass(arr[arrLen - k], arr[arrLen - (k - 1)])) {
752                                canCommute = false;
753                                break;
754                            }
755                        }
756                    }
757                    if (canCommute) {
758                        var moveAdd = {
759                            base: arr[arrLen - j].base,
760                            amount: normalize(arr[arrLen - j].amount + arrayAdd.amount)
761                        };
762                        if (moveAdd.amount === 0) {
763                            arr.splice(-j, 1);
764                        }
765                        else {
766                            arr.splice(-j, 1, moveAdd);
767                        }
768                        isChange = true;
769                        break;
770                    }
771                }
772            }
773        }
774        if (!isChange) {
775            arr[arrLen] = arrayAdd;
776        }
777    }
778    return arr;
779}
780function isSameClass(move1, move2) {
781    if (move1.base in commute && move2.base in commute) {
782        if (commute[move1.base]["class"] === commute[move2.base]["class"]) {
783            return true;
784        }
785    }
786    return false;
787}
788function swapArray(array, index1, index2) {
789    array[index1] = array.splice(index2, 1, array[index1])[0];
790    return array;
791}
792function normalize(amount) {
793    if (isOrderZero) {
794        return amount;
795    }
796    return (((amount % order) + order - minAmount) % order) + minAmount;
797}
798function commutator(algorithm) {
799    return search({algorithm})[0];
800}
801function expand(algorithm) {
802    return expandOrigin({algorithm});
803}

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.