⭐️  [ Kt, Js, Py3, Cpp ] 🎯  Concise Simulation
Kotlin\n\nclass Solution {\n    fun reinitializePermutation(N: Int): Int {\n        var cnt = 0\n        var A = IntArray(N) { it }\n        var target = A.join
*Kotlin*\n```\nclass Solution {\n    fun reinitializePermutation(N: Int): Int {\n        var cnt = 0\n        var A = IntArray(N) { it }\n        var target = A.joinToString("")\n        do {\n            var pre = A.copyOf()\n            for (i in 0 until N) {\n                if (i % 2 == 0) A[i] = pre[i / 2]\n                if (i % 2 == 1) A[i] = pre[N / 2 + (i - 1) / 2]\n            }\n            ++cnt\n        } while (A.joinToString("") != target)\n        return cnt\n    }\n}\n```\n\n*Javascript*\n```\nlet reinitializePermutation = (N, cnt = 0) => {\n    let A = [...Array(N).keys()]\n    let target = A.join(\'\');\n    do {\n        let pre = [...A];\n        for (let i = 0; i < N; ++i) {\n            if (i % 2 == 0) A[i] = pre[Math.floor(i / 2)];\n            if (i % 2 == 1) A[i] = pre[Math.floor(N / 2) + Math.floor((i - 1) / 2)];\n        }\n        ++cnt;\n    } while (A.join(\'\') != target);\n    return cnt;\n};\n```\n\n*Python3*\n```\nclass Solution:\n    def reinitializePermutation(self, N: int, cnt = 0) -> int:\n        A = [i for i in range(N)]\n        target = A[:]\n        while True:\n            pre = A[:]\n            for i in range(N):\n                if i % 2 == 0: A[i] = pre[i // 2]\n                if i % 2 == 1: A[i] = pre[N // 2 + (i - 1) // 2]\n            cnt += 1\n            if A == target:\n                break\n        return cnt\n```\n\n*C++*\n```\nclass Solution {\npublic:\n    using VI = vector<int>;\n    int reinitializePermutation(int N, int cnt = 0) {\n        VI A(N);\n        iota(A.begin(), A.end(), 0);\n        auto target{ A };\n        do {\n            auto pre{ A };\n            for (auto i{ 0 }; i < N; ++i) {\n                if (i % 2 == 0) A[i] = pre[i / 2];\n                if (i % 2 == 1) A[i] = pre[N / 2 + (i - 1) / 2];\n            }\n            ++cnt;\n        } while (A != target);\n        return cnt;\n    }\n};\n```
[]