如何在BrainFuck中将指针移动任意量?
例如,如果数组类似于 0 0 0 0 ... 0 0[n]somedata 4 9 9 9 9 9 9 8 3 7 ...
,如何将指针移动 n,指针移动后不改变 somedata 4 9 9 9 ...
?
For example, if the array is like 0 0 0 0 ... 0 0[n]s o m e d a t a 4 9 9 9 9 9 9 8 3 7 ...
, how to move the pointer by n, without changing s o m e d a t a 4 9 9 9 ...
after the pointer is moved?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
很好的挑战。我喜欢这种语言:)
我的解决方案(我认为)有点正确,它将光标移动到长度为 n 的数据之后而不改变它,但是它将数据向左移动两个单元格(或一个,前提是满足一定的条件)。这是代码,希望您觉得有用。
要求是:
代码如下:
示例:数组
7 9 6
,因此3
告诉光标移动多远。现在,如果整个序列的左侧有一个额外的空单元格,那么我们可以将数据向右移动一个单元格。
因此,光标移动到任意长度的数据后面,但是将数据向左移动一个单元格。
免责声明代码中可能有错误,但想法本身应该是清晰的。只要代码与示例不匹配,请随时更正该代码。
Nice challenge. I love this language :)
My solution is (I think) somewhat correct, it moves the cursor after the data of length n without changing it, but it moves the data two cells to the left (or one, provided certain conditions are met). Here is the code, hope you find it useful.
The requirements are:
Here is the code:
Example: an array
7 9 6
, so3
tells how far to move the cursor.Now, if there is an additional empty cell to the left of the whole sequence, then we can move the data one cell to the right.
So the cursor is moved behind the data of an arbitrary length, however shifting the data one cell to the left.
Disclaimer There might be errors in the code, but the idea itself should be clear. Feel free to correct the code whenever it does not match the example.
这可能太明显了,但您可以使用
[>]
或[<]
将指针滑动到下一个零。那么你可以在数据单元格中加 1(打包一个 peano)并在输出之前减 1 ([-.>]
) 吗?遗憾的是,这可能无法提供足够精细的控制。
This may be too obvious, but you can slide the pointer to the next zero, with
[>]
or[<]
. So can you add 1 to your data cells (packing a peano) and subtract 1 before output ([-.>]
)?Sadly, this may not offer fine enough control.