编码/解码ID冲销问题 [英] Encode/Decode ID Reversal issue

查看:354
本文介绍了编码/解码ID冲销问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


  • SCENARIO:



>您有字符集 100 其中第一个字符 A,B,C 和最后的字符是 - ,_



B) encode 函数返回一个长度为 10



C) 编码转换 code>进入字符集中的相关数字



示例: A == 0 || B == 1 || C == 2 || - == 98 || _ == 99



code> 100 ^ 10 = 1e + 20 || 100,000 Quadrillion || 100,000,000,000美元




  • 问题:确定 999 iii _i 还是 i _


  • 让我们来看看我们的问题:

    $

    b
    $ b

    999不能表示为字符集中的单个字符
    我们可以以3种不同的方式对它进行编码



    9 9 9 => III



    99 9 => _I



    9 99 => I _



    现在...一个字符集本身不会进行编码...在这一点上,你应该可以阅读一下代码是什么... http://en.wikipedia.org/wiki/Code



    请注意,这绝对与加密无关...



    所以...我们需要一个规则集来编码/解码我们的代码



    因为我们应该创建这个规则集,所以我们可以自由选择处理事物的方式,只要我们记住我们必须遵循的其他关键规则...



    代码应该是10个字符长...在我看到的最大值,否则III不可能是我们的代码的有效示例... AAAAAAAAIII将... ...所以让我们假设我们可以删除前导零,或者在这种情况下,进一步假设III和AAAAAAAIII是相同的



    现在我们有一个事实, 100 ^ 10个可能的码字,如果每个长度为10的字符集的每个组合都是有效的码字,则只能被捕获。



    所有三个... III和I_和_I ...必须是有效的代码字...



    这意味着所有三个值都为999?



    short:no



    long:



    给代码一个含义...



    因为没有给出编码规则集,我们似乎可以自由创建一个...



    让我们看一下规则集来编码我们的常规基数10个数字...



    我们有一个字符集从0到9 - > 10数字



    数字中数字的位置包含信息...



    123例如可以写入如果我们将它转​​移到我们的新编码...,我们称之为100。如果我们将它转​​换为100,则为1 * 10 ^ 10 + 2 * 10 ^ 1 + 3 * 10 ^ 0



    ..它看起来像这样:



    123 - > 1 * 100 ^ 1 + 23 * 100 ^ 0



    => 1 = B ... 23 = X => 123 - > BX



    999 - > 9 * 100 ^ 1 + 99 * 100 ^ 0 - > I _



    但是谁说我们必须声明代码中最左边的数字是最重要的数字?



    <

    不是99 * 100 ^ 0 + 9 * 100 ^ 1 = 999太?



    是...因此我们可以把它写成_I太...



    哪一个是正确的? ...只取决于我们的代码的规则集...如果它说最左边的数字是最重要的一个,答案是I_ ...如果最右边的数字是最重要的一个,答案是_I



    只要未指定编码的规则集,此问题的答案无法解决...您只能尝试进行有根据的猜测,并使用相同的约定在我们的正常基础10编码...最左边的数字=最高有效数字 - > I _



    但请记住...这是一个猜测。如果我在测试中得到这样的问题,我会解释为什么除非编码规则被指定,否则没有答案。



    tldr:



    与提供的信息,如果它是i_或_i


    是一个自由选择
    • SCENARIO:

    A) You have a charset of 100 in which the first characters are A, B, C and the last characters are -, _.

    B) The encode function returns a string of length 10.

    C) The encode converts a number into the correlating number in the charset

    Example: A == 0 || B == 1 || C == 2 || - == 98 || _ == 99

    Amount of possibilities: 100 ^ 10 = 1e+20 || 100,000 Quadrillion || 100,000,000,000 Billion.

    • PROBLEM: How would you figure out whether 999 is iii, _i or i_?
    • Note: The solution to the problem sketched above should work for every possible situation

    解决方案

    looks like homework...

    lets have a look at our problem:

    999 can not be represented as a single char in our charset we can encode it in 3 different ways

    9 9 9 => I I I

    99 9 => _I

    9 99 => I_

    now... a charset alone does not make an encoding ... at this point you should probably read up about what a "code" is ... http://en.wikipedia.org/wiki/Code

    please notice that this has absolutely nothing to do with encryption ...

    so ... we need a ruleset for encoding/decoding our code

    since we are supposed to make that ruleset, it is our free choice how we handle things, as long as we keep in mind what other key rules we have to follow...

    the code shall be 10 characters long ... at max from what i see, or else III wouldn't possibly be a valid example of our code ... AAAAAAAAIII would be ... so lets assume that we may drop leading zeros, or As in this case, and further assume that III and AAAAAAAIII are identical

    now we have the given fact that our code has 100^10 possible codewords, which can only be achived if every combination of our charset with a length of 10 is a valid codeword

    so all three ... III and I_ and _I ... have to be valid codewords ...

    does that mean that all three have the value of 999?

    short: no

    long:

    as mentioned earlier, there is a ruleset needed to give the code a meaning...

    since there is no encoding ruleset given, we seem to be free to create one...

    lets have a look at the ruleset to encode our regular base 10 numbers ...

    we have a charset from 0 to 9 -> 10 digits

    the position of a digit in a number contains information...

    123 for example can be written as 1*10^10 + 2*10^1 + 3*10^0

    if we transfer this to our new encoding ... let's call it base 100 ... it would look like this:

    123 -> 1*100^1 + 23*100^0

    => 1=B ... 23=X => 123 -> BX

    999 -> 9*100^1 + 99*100^0 -> I_

    but who says we have to declare the left most digit in our code to be the most siginificant digit?

    what if we would interpret it otherwise?

    isn't 99*100^0 + 9*100^1 = 999 too?

    yes ... therefore we could write it as _I too ...

    which one is the correct one now? ... that ONLY depends on the ruleset of our code ... if it says the leftmost digit ist the most significant one, the answer is I_ ... if the rightmost digit ist the most significant one, the answer is _I

    as long as the ruleset for the encoding is not specified, the answer to this question cannot be solved ... you can only try to make an educated guess, and use the same convention as in our "normal" base 10 encoding ... leftmost digit = most significant digit -> I_

    but please keep in mind ... this is a guess ... if i'd get such a question in a test, i'd explain why there is no answer unless the encoding rules have been specified.

    tldr:

    with the provided information, it's a free choice if it is i_ or _i

    这篇关于编码/解码ID冲销问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆