Brainfuck 比较 2 个数字大于或小于
如何比较两个不等式的数字? (大于或小于)
我想比较个位数 例如
1 2
5 3
9 2
等等。
How can I compare two numbers with an inequality? (greater than or less than)
I want to compare single digits
For example
1 2
5 3
9 2
etc.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
这是比较两个数字的最佳方法。为什么是因为,如果您足够聪明,您可以在更大的程序中使用相同的代码。它具有高度可移植性。
假设我们有两个数字a,b。
我们有两个块:if( a>=b ) 和 else,
希望它足够了。
使数组像这样。并指向 (4) 即指向 a
它不会影响下面的程序代码,因为两个代码块都将在 (1) 中结束 您可以假设指针将到达 ( 1)
如果复制代码,请删除文档。因为代码包含一些有效的 Brainfuck 符号,例如 < 。 , ETC。
This is the best way to compare two numbers.Why because, if you are intelligent enough, you can use the same code in bigger programs.It's highly portable.
Assume we have two numbers a,b.
we have two blocks : if( a>=b ) and else,
Hope its enough.
Make the array like this. And point to the (4) i.e. point to the a
It will not affect the following program code as both the code blocks will end up in (1) You can do further coding assuming that pointer will reach (1)
Please remove the documentation if you copy the code. Because code contains some valid brainfuck symbols like < . , etc.
一旦您知道两个数字之间的距离,您应该在同一个循环迭代中减少这两个数字,然后检查两个数字是否为零:您将了解哪个数字较小。
例如:(
这只是给你一个提示,你必须注意相等的数字和类似的问题。
Once you know which is the distance between the two numbers you should or decrement both of them in the same loop iteration and then check both for being zero: you will understand which one is the smaller.
Eg:
(this is just to give you a hint, you will have to take care about equal numbers and similar issues.
我也在考虑这个问题,虽然我确信这不是最好的解决方案,但至少它可以回答哪个数字更大的问题 =)
程序要求两个字符,输出 '<'如果第一个较小,则“>”如果更大,则为“=”,如果相等则为“=”。输出一个字符后,程序会通过要求额外的输入而停止。
+>,>,<<[>-[>>>]<[>>-[>++++++++++[-> ;++++++<]>.,]++++++++++[->++++++<]>+.,]<-[> >>]<<[>>++++++++++[->++++++<]>++.,]<< <]
希望更清楚一些:
I was thinking about this too, and while I'm sure this isn't the best solution, at least it can answer the question of which number is larger =)
The program asks for two characters, outputs '<' if the first is smaller, '>' if it is larger, and '=' if they are equal. After outputting one char, the program halts by asking for additional input.
+>,>,<<[>-[>>>]<[>>-[>++++++++++[->++++++<]>.,]++++++++++[->++++++<]>+.,]<-[>>>]<<[>>>++++++++++[->++++++<]>++.,]<<<]
Hopefully somewhat clearer:
我提出了一个解决方案,它返回一个布尔值,并且指针始终位于同一点。
这是它一开始的样子:
这是两个可能的输出:
代码:
缩小版本:
I made a solution, that gives you back a boolean and the pointer always at the same point.
This is how it looks like at the beginning:
And these are the two possible outputs:
The code:
minified version:
给定两个数字 A 和 B,如果 A 大于 B,则以下代码将打印 A;如果 B 大于 A,则打印 B;如果两者相等,则以下代码将打印 C。
>>>>>>>>>++++++[>+++++++++++<-]>[> +>+>+<<<-]>+>->
<<<<<<<<<<<<<<,>,<
[->-<[>]<<]>>>[>>]>>>>>>>>。
Given two numbers A and B, the following code will print A if A is greater than B, B if B is greater than A and C if both are equal.
>>>>>>>>>++++++[>+++++++++++<-]>[>+>+>+<<<-]>+>->
<<<<<<<<<<<,>,<
[->-<[>]<<]>>>[>>]>>>>>>>>.
BF里不存在这样的东西。 BF 中的
>
和<
分别将指针向右和向左移动。No such thing exists in BF. The
>
and<
in BF move the pointer to the right and to the left, respectively.