Execute Brain****/D: Difference between revisions

Content added Content deleted
(Better second D entry)
m (Fixed syntax highlighting.)
 
Line 1: Line 1:
{{implementation|Brainf***}}{{collection|RCBF}}
{{implementation|Brainf***}}{{collection|RCBF}}
===Version 1===
===Version 1===
<lang d>import core.stdc.stdio, core.stdc.stdlib, std.conv;
<syntaxhighlight lang="d">import core.stdc.stdio, core.stdc.stdlib, std.conv;


void brainfuckRun(in dstring code) nothrow {
void brainfuckRun(in dstring code) nothrow {
Line 87: Line 87:
+++.------.--------.>+.>.");
+++.------.--------.>+.>.");
}
}
}</lang>
}</syntaxhighlight>


===Version 2===
===Version 2===
Much faster version, code generated at compile-time, run at run-time:
Much faster version, code generated at compile-time, run at run-time:
<lang d>string ctbf(in string code) pure nothrow {
<syntaxhighlight lang="d">string ctbf(in string code) pure nothrow {
string r;
string r;
foreach (immutable c; code)
foreach (immutable c; code)
Line 261: Line 261:
+[-[->>>>>>>>>+<<<<<<<<<]>>>>>>>>>]>>>>>->>>>>>>>>>>>>>>>>>>>>>>>>>>-<<<<<<[<<<<
+[-[->>>>>>>>>+<<<<<<<<<]>>>>>>>>>]>>>>>->>>>>>>>>>>>>>>>>>>>>>>>>>>-<<<<<<[<<<<
<<<<<]]>>>]"));
<<<<<]]>>>]"));
}</lang>
}</syntaxhighlight>
LDC2 compiles this with full optimizations in 2.3 seconds, and the BF runs in less than 1.1 seconds.
LDC2 compiles this with full optimizations in 2.3 seconds, and the BF runs in less than 1.1 seconds.