Brainfuck的绝对数量
您将如何在Brainfuck中获得绝对的数字?
我最初以为将数字平方( [ - >+>+<<<] +>+<<]>> [ - <<<+>>><<<<< - ]
))和平方生根会起作用,但我无法正常想想一种通向平方根的方法。
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
计算数字绝对的一种方法是确定其标志。如果您知道您的程序如何表示负数,则会有一个 /u/u/u/danielcristofani 一个数字,你可以
如有必要,然后应应用
x = -x
算法,例如其包装版本:One way to compute the absolute of a number is to identify its sign. If you know how your program represents negative numbers, there is a reddit answer by /u/danielcristofani that explains that, in order to check for the sign of a number, you can
If necessary, you should then apply an
x = -x
algorithm, for example its wrapping version:我们可以做得更好。从0 x 0 0开始,从x处的指针开始,
结果在0 0 | x | 0用指针在四个的最左侧单元格。这假设数字在通常的两个补体表示中,其中255 = -1和254 = -2,依此类推(如果单元格为字节)。这反过来假设在处理数字之前,该程序一直在谨慎地不超过127或下流,超过了-128。可行,但根据这些数字所做的事情,最好从一开始分开表示标志。
We can do a bit better than that. Beginning with 0 x 0 0 with the pointer at x,
results in 0 0 |x| 0 with the pointer at the leftmost cell of the four. This assumes the number was in the usual two's complement representation, where 255 = -1 and 254 = -2 and so on (if cells are bytes). Which in turn assumes that in handling numbers up to this point, the program has been careful not to overflow past 127 or underflow past -128. Doable, but depending what's being done with these numbers it might be better to represent the sign separately from the beginning.