Mapping from “int” to corresponding permutation value?

前端 未结 1 1491
逝去的感伤
逝去的感伤 2021-01-27 05:49

I ran across this question this morning.

Basically that question is about data which has to create permutations for 6 values; each one ranging from 1 to 38.

So,

相关标签:
1条回答
  • 2021-01-27 06:14

    It works exactly like a change of base (binar, octal or hex). The first one question simply: 1*38^6 + 2*38^5 + 3*38^4 + 4*38^3 +...+6*38^0 The second one reversed: 102382 mod 38... recursively UPDATE Let us assume we want change 10 to base 2:

    10/2=5 remainder(modulus)  **0** 
    5/2=2 remainder           **1**
    2/2=1 remainder           **0**
    1/2=0 remainder           **1**
    

    backwards is 1010 general gave a M to change in base B, just divide M by B , and the remainder are going to be the digit in the new base

    0 讨论(0)
提交回复
热议问题