计算2位数字的平均值
如何用brainfuck计算2位数字的平均值?
我的意思是我有两位数字 2 3
其平均值为 2.5
2 8
我们有 5.0
这是怎么做到的?
How to calculate average of 2 digits with brainfuck ?
I mean i have two digits for example2 3
and its average is 2.5
for2 8
we have5.0
How can this be done?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
大致意思是:
该方法是将两个数字的总和均匀分布。通过均匀分布我的意思是值之间的差异最多为1(因为没有浮点数,所以你必须以某种方式表示例如2.5)。一旦您有两个包含这些值的相邻单元格,请随意对它们执行任何您想要的操作(您可以输出它,然后减少每个单元格中的数字,如果剩下 1,则向其输出“.5”)。
当然,上面的代码可能存在指针错误,但对于启动和调试来说应该足够了。此外,我真的很高兴看到一个好的、高效的解决方案。
Something along the lines of:
The approach is to evenly distribute a sum of two numbers. By evenly distribute I mean that the difference between values is at most 1 (since there are no floating point numbers, you have to somehow represent e.g. 2.5). Once you have two neighbouring cells containing these values, feel free to do whatever you want with them (you can output it, then decrease numbers from each cell and if you are left with 1, then output ".5" to it).
Of course, the code above may have pointer errors, but it should be enough for a start and to debug. Furthermore, I would be really happy to see a good, efficient solution.
更好的解决方案:
better solution: