javascript direct way with endless loop 96ms
\nconst reinitializePermutation = (n) => {\n    let perm = [];\n    for (let i = 0; i < n; i++) perm.push(i);\n    let origin = [...perm];\n    let res = 0;\n  
```\nconst reinitializePermutation = (n) => {\n    let perm = [];\n    for (let i = 0; i < n; i++) perm.push(i);\n    let origin = [...perm];\n    let res = 0;\n    while (1) {\n        let a = [...perm];\n        for (let i = 0; i < n; i++) {\n            let idx;\n            if (i & 1) {\n                idx = (n >> 1) + (i - 1) / 2;\n            } else {\n                idx = i / 2;\n            }\n            a[i] = perm[idx];\n        }\n        perm = a;\n        res++;\n        if (arrayEquals(origin, perm)) {\n            break;\n        }\n    }\n    return res;\n};\n\nconst arrayEquals = (a, b) => {\n    return a.length === b.length && a.every((v, i) => v === b[i]);\n};\n```
['JavaScript']