问题标签 [brainfuck]
For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.
if-statement - 如何检查brainf * ck中的两个细胞是否相等?
如何检查单元格#0 中的值是否等于单元格#1 中的值?我正在尝试编写等效于:
我读过Brainfuck 比较 2 个数字大于或小于,第二个答案让我大致了解了我需要做什么,但我无法弄清楚。(该解决方案给出了if a < b, else
。)
我想我需要按照递减这两个值的方式做一些事情,如果它们同时达到 0,那么它们就是真的。但每次我想到它时,我总是被困在同一个出口点。
如何在brainfuck中检查两个细胞是否相等?
brainfuck - 在 Brainfuck 中读取命令行参数
任何人都可以帮助我解释 Brainfuck 程序中的命令行参数(如果可能的话),因为其他语言(如 C)读取它们?例如
gcc cmd.c arg1 arg2
我在我的 Ubuntu 机器上安装了以下解释器-
bf - Brainfuck 解释器版本 20041219 (C) 2003, 2004, Stephan Beyer, GPL, s-beyer@gmx.net
以下是传统上可能的还是有一些技巧的?
bf cmd.bf arg1 arg2
brainfuck - 如何让 Brainf_ck 程序“休眠”?
是否真的可以让 Brainfuck 代码/程序“睡眠”例如 x 秒或类似时间?
肯定循环一个大数字直到它下降到 0 现在不可能,是吗?它可能不是真正可靠或一致的。
while-loop - 在brainfuck中高效实现while循环
我在为 codegolf.se 实现一个笨拙的汇编程序时遇到了麻烦。我设法将一个字符串加载到内存中,找到它的长度,打印字符串 n 次等,但我似乎不能只将非小写数字加载到内存中。因此,让我们采用以下循环来执行一些魔法。(哈希标记是调试标记。)
它从指针 512 开始,并将字符串作为 ascii 值写入 512 之后的点
现在,如果(无论出于何种原因)我希望去掉小写字符,它会在伪 BF 中看起来像这样。
现在我的问题是,如何在仅使用 512 右侧的空格作为存储并稍后清除它们的同时实现这样的 while 循环。
对于那些好奇的人,这是我希望在 branfuck 中解决的问题。
c++ - 代码长度或磁带大小:brainf ...(munged)
磁带大小最好比brainfuck的程序大小长吗?还是反过来更好?
另外,相对于彼此有多大?
我正在尝试为 Arduino 做一个笨拙的解释器。我知道这已经完成了,但我正在添加诸如Adafruit 显示和代码编写能力之类的东西。
因此,代码很长,特别是因为我将代码和磁带都存储在数组中:
内存应该至少包含 30000 个单元,一些现有的 Brainfuck 程序确实需要更多,所以这应该是可配置的或无界的。
我知道我永远不会将 30000 个单元格放入 Uno,但似乎动态内存是从中获得最大空间的方法。任何这样做的方式都值得赞赏。
目前,char code[512] = {};
并byte tape[1024] = {};
使用“1,807 字节(88%)的动态内存”,但这只是解释器草图。我还需要在其中压缩更多代码。代码在这里,任何有兴趣的人都可以使用。
parsing - 将brainf * ck代码解析为Rust中的树
我正在尝试用 Rust 编写一个优化的 Brainfuck 编译器。目前它将标记存储在一个平面向量中,这可以工作,但我无法将其更改为使用语法树:
我无法弄清楚如何处理[
命令。代码中的当前实现是我尝试过的几个之一,但都失败了。我认为它可能需要使用 Rust Box
,但我不太明白它是如何使用的。
处理命令的分支[
可能完全错误,但我不确定应该如何完成。它将包含向量Loop
的(枚举的变体)推送到向量。问题是然后在 that 中获得向量的可变借用,这是语句应该做的。Token
tokens
Loop
if let
该代码无法编译,因为newtokens
它没有超过块的末尾if let
。是否可以获得对内部向量的可变引用Loop
并设置tokens
为它?如果没有,可以做些什么呢?
c - Brainfuck翻译问题
我是 C 的新手。目前我正在尝试编写一个 Brainfuck 解释器。到目前为止,我已经尝试过了。
它只能在没有循环的情况下工作(“[”和“]”)。当我尝试时:
它给了我输出
预期输出:
algorithm - 深奥的编程和我的分析
最近遇到一个关于深奥编程语言的问题。有那种语言的工具。
所以我必须用这种语言编写一个程序,输入 2 个数字 a 和 b 并将它们放入 cell0 和 cell1,然后输出这两个数字的总和。还有一个额外的要求(我遇到了麻烦)是在这个过程之后应该有 3 个单元格,cell0 保存 a,cell1 保存 b,cell 2 保存 a+b。
这是我的分析:我认为找到将总和放入 cell3 并打印它的方法很容易,只需;>;<[->>+]>[->+]>:
. 但是这样处理后,cell0 和 cell1 都将保持 0 而不是 a 和 b。所以我试图找到一种方法来使用上面的工具来实现这一点,我意识到给定工具,它就像一个电池,我只能将能量从一个电池转移到另一个电池,但我永远无法将能量从一个电池复制到另一个. 如果是这样,当我试图保留 cell0 和 cell1 时,我永远无法得到总和。
感谢我的问题下的@user3386109评论信息。我注意到有办法欺骗“能量平衡”。我们可以在循环中增加 2 个或更多单元格。所以我使用 5 个单元格并将第一个单元格和第二个单元格中的 a 和 b 转移到第 4 个和第 5 个单元格中,同时进行求和运算。所以我的算法会是这样的:
所以最后我的代码是:
但这是不对的,我检查了几次并找不到错误。有人帮我吗?谢谢!!!
c++ - Why is std::map making my code so bloated?
My latest recreational project is to write a brainfuck interpreter in C++. It was straightforward enough but today I decided to add to it by an compilation step. The eventual goal is to be able to create executables but right now all it does is some basic optimization. For instance +++++ is turned for 5 add 1 commands into a single add 5 and so on.
While this works well, I've noticed that the size of my executable after being stripped has gone from 9k to 12k. After some research I've determined the function below is to blame, specifically the map. I do not understand why.
The key in the map is one of the 8 valid Brainfuck operations. The function goes through the input string and looks for these valid characters. An invalid character is just skipped as per the Brainfuck spec. If it finds one it passes the map value for that key to a function called makeop that does optimization, turns it into an op struct and adds it to the vector of instructions that my interpreter will actually execute.
The op struct has two members. An Opcode, which is a scoped enum based on a uint8_t representing one of the 8 operations, and one int containing the operand. (one operand for now. A future more sophisticated version might have instructions with multiple operands.) So in the +++++ example above the struct would contain Opcode::INCR and 5.
So the value of each map entry is a std::pair consisting of the Opcode, and the number of operands. I realize that some overhead is inevitable with a generic data structure but given the simplicity of the description above, don't you think 3k is a bit excessive?
Or perhaps this is not the right approach to achieve my aim efficiently? But if not a std::map then which data structure should I use?
Update:
Thanks to all those who responded. First, a few words about my motives. I don't use C++ in my day job that often. So I'm doing some recreational projects to keep my knowledge sharp. Having the absolutely smallest code size is not as important as e.g. clarity but it is interesting to me to learn how bloat and such things happen.
Following the advice given, my function now looks like this:
I recompiled and...nothing happened. I remembered that I had another method which contained a map and a (now deleted?) response suggested that merely having an instantiation of map would be enough to add code. So I changed that map to an array to and recompiled again. This time the stripped size of my executable went from 12280 to 9152.
python - 即使 2 个变量中只有 1 个为真,循环也会停止
所以我正在尝试制作一个 Brainfuck 解释器,但是在我用来执行 Brainfuck 循环的 while 循环中,即使只有一个条件为真,它也会中断。
例子:
应该导致:
但是,当循环从 开始时[
,它将创建一个新单元格,因此结构从[3]
到[3, 0]
。因此,当前的工作单元是0
并且循环正在中断。但是,我只有在它是0
并且当前字符是]
.
先感谢您。