为什么Befunge代码9332682811> \#+:#* 9 - #\ _ $。@输出52256370?

时间:2017-07-20 18:56:04

标签: befunge

今天我尝试在Esolangs.orgesoteric programming languages维基上创建一个帐户。我之前为一些wiki做过贡献,我想做一两页次要的页面编辑。

...就是说,直到我看到用于创建新帐户的CAPTCHA验证拼图。

Captcha puzzle for Esolangs.org

对于CAPTCHA使用一种模糊的语言很可能是一个愚蠢的开玩笑。但是,我花了近半个小时试图理解语言,所以我可以创建一个新帐户。

最终我放弃并使用了online Befunge interpreter,它给了我答案52256370

我不明白为什么 9332682811>\#+:#*9-#\_$.@的输出为52256370

我已经看到一些评论表明它是从10-base转换为9-base。但是,当我尝试通过将9332682811转换为online base converter进行验证时,我得到26072072027的结果。

1 个答案:

答案 0 :(得分:4)

该程序将332682811解析为little-endian base-9整数,并将其打印在base-10中。

Befunge使用可在两个维度上自由移动的指令指针解释2D网格(或环面,取决于版本)上的指令。该程序是一行的,因此指令指针只能前后移动。

9332682811将这些数字分别推送到Befunge的值堆栈,然后以下指令执行一个简单的循环。在循环的正常迭代中,事情看起来像这样:

Instructions              Meaning                                       Top stack values

9332682811>\#+:#*9-#\_$.@
          >               Set the instruction pointer to travel         a b
                          to the right.
           \              Swap the top 2 values on the stack.           b a
            #+            Nothing, since # means                        b a
                          skip the next instruction.
              :           Duplicate the top value on the stack.         b a a
                 9        Push 9.                                       b a a 9
                  -       Pop two values and push their difference.     b a (a-9)
                     _    Pop the top value and set the instruction     b a
                          pointer traveling right if the value is 0
                          or left otherwise.
                    \     Swap the top 2 values.                        a b
                 9        Push 9.                                       a b 9
                *         Pop two values and push their product.        a (b*9)
             +            Pop two values and push their sum.            (b*9 + a)
          >               Set the instruction pointer traveling
                          right again.

因此,除非迭代开始时堆栈上的第二个值为9,否则迭代会弹出两个值ba并推送b*9 + a

如果第二个值 9,则循环终止并打印最高值:

Instructions              Meaning                                       Top stack values

9332682811>\#+:#*9-#\_$.@
                     _    Pop the top value and set the instruction     b a
                          pointer traveling right if the value is 0
                          or left otherwise.
                      $   Discard the top value.                        b
                       .  Pop and print the top value.
                        @

因此,总而言之,该程序推送了一堆数字,并用a重复替换bb*9+a,直到它达到9,信号停止。这是一个基础9转换器。

如果您尝试使用another base converter验证这一点,请确保您获得正确的字节顺序。 332682811是小尾数,因此您可能需要撤消它。