function shuffleArray(array) {
for (let i = array.length - 1; i > 0; i--) {
const j = Math.floor(Math.random() * (i + 1));
[array[i], array[j]] = [array[j], array[i]]; // Swap elements
}
}
function merge(arr1, arr2) {
const merged = [];
let i = 0;
let j = 0;
while (i < arr1.length || j < arr2.length) {
if (Math.random() < 0.5 && i < arr1.length) {
merged.push(arr1[i]);
i++;
} else if (j < arr2.length) {
merged.push(arr2[j]);
j++;
}
}
return merged;
}
function f(n) {
const zoos = [0, 1, 10];
const zoo = [];
const result = [];
for (let i = 0; i < 12; i++) {
if ((1 << i) & n) {
if (zoos.includes(i)) {
zoo.push(i);
} else {
result.push(i);
}
}
}
shuffleArray(result);
return(merge(result, zoo).join(''));
}
function g(s) {
let r = 0;
let i = s.length - 1;
while (i >= 0) {
if (i > 0
&& ['10', '11'].includes(s[i-1] + s[i])) {
r += 1 << Number(s[i-1] + s[i]);
i -= 1;
} else {
r += 1 << Number(s[i]);
}
i -= 1;
}
return r;
}
const n = 176
const ff = f(n)
print(ff);
print(g(ff));
CmZ1bmN0aW9uIHNodWZmbGVBcnJheShhcnJheSkgewogIGZvciAobGV0IGkgPSBhcnJheS5sZW5ndGggLSAxOyBpID4gMDsgaS0tKSB7CiAgICBjb25zdCBqID0gTWF0aC5mbG9vcihNYXRoLnJhbmRvbSgpICogKGkgKyAxKSk7CiAgICBbYXJyYXlbaV0sIGFycmF5W2pdXSA9IFthcnJheVtqXSwgYXJyYXlbaV1dOyAvLyBTd2FwIGVsZW1lbnRzCiAgfQp9CgpmdW5jdGlvbiBtZXJnZShhcnIxLCBhcnIyKSB7CiAgY29uc3QgbWVyZ2VkID0gW107CiAgbGV0IGkgPSAwOwogIGxldCBqID0gMDsKCiAgd2hpbGUgKGkgPCBhcnIxLmxlbmd0aCB8fCBqIDwgYXJyMi5sZW5ndGgpIHsKICAgIGlmIChNYXRoLnJhbmRvbSgpIDwgMC41ICYmIGkgPCBhcnIxLmxlbmd0aCkgewogICAgICBtZXJnZWQucHVzaChhcnIxW2ldKTsKICAgICAgaSsrOwogICAgfSBlbHNlIGlmIChqIDwgYXJyMi5sZW5ndGgpIHsKICAgICAgbWVyZ2VkLnB1c2goYXJyMltqXSk7CiAgICAgIGorKzsKICAgIH0KICB9CgogIHJldHVybiBtZXJnZWQ7Cn0KCmZ1bmN0aW9uIGYobikgewogIGNvbnN0IHpvb3MgPSBbMCwgMSwgMTBdOwogIGNvbnN0IHpvbyA9IFtdOwogIGNvbnN0IHJlc3VsdCA9IFtdOwogIGZvciAobGV0IGkgPSAwOyBpIDwgMTI7IGkrKykgewogICAgaWYgKCgxIDw8IGkpICYgbikgewogICAgICBpZiAoem9vcy5pbmNsdWRlcyhpKSkgewogICAgICAgIHpvby5wdXNoKGkpOwogICAgICB9IGVsc2UgewogICAgICAgIHJlc3VsdC5wdXNoKGkpOwogICAgICB9CiAgICB9CiAgfQogIHNodWZmbGVBcnJheShyZXN1bHQpOwogIHJldHVybihtZXJnZShyZXN1bHQsIHpvbykuam9pbignJykpOwp9CgpmdW5jdGlvbiBnKHMpIHsKICBsZXQgciA9IDA7CiAgbGV0IGkgPSBzLmxlbmd0aCAtIDE7CiAgd2hpbGUgKGkgPj0gMCkgewogICAgaWYgKGkgPiAwCiAgICAgICYmIFsnMTAnLCAnMTEnXS5pbmNsdWRlcyhzW2ktMV0gKyBzW2ldKSkgewogICAgICByICs9IDEgPDwgTnVtYmVyKHNbaS0xXSArIHNbaV0pOwogICAgICBpIC09IDE7CiAgICB9IGVsc2UgewogICAgICByICs9IDEgPDwgTnVtYmVyKHNbaV0pOwogICAgfQogICAgaSAtPSAxOwogIH0KICByZXR1cm4gcjsKfQoKY29uc3QgbiA9IDE3Ngpjb25zdCBmZiA9IGYobikKcHJpbnQoZmYpOwpwcmludChnKGZmKSk7