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

Content added Content deleted
m (adding links)
m (Categorization now in master page)
Line 1: Line 1:
{{implementation|Brainf***}}{{collection|RCBF}}[[Category:Erlang]]
{{implementation|Brainf***}}{{collection|RCBF}}
Implementation of a [[Brainfuck]] interpreter in [[Erlang]].
Implementation of a [[Brainfuck]] interpreter in [[Erlang]].


Line 6: Line 6:
The opcodes also use a binary representation, which allows to jump through the loop structures. Note, however, that finding the end of the loop still requires linear time, which could be improved.
The opcodes also use a binary representation, which allows to jump through the loop structures. Note, however, that finding the end of the loop still requires linear time, which could be improved.


<lang erlang>
<lang erlang>-module(brainfuck).
-module(brainfuck).
-export([run/1]).
-export([run/1]).


Line 66: Line 65:
find_end(Ins, N+1, Pos+1);
find_end(Ins, N+1, Pos+1);
find_end(<<_, Ins/binary>>, N, Pos) ->
find_end(<<_, Ins/binary>>, N, Pos) ->
find_end(Ins, N, Pos+1).
find_end(Ins, N, Pos+1).</lang>

</lang>


Example output, the first one being the usual 'Hello World!' program and the second one testing nested loops to increment count to 64 and print the result (should be '@'):
Example output, the first one being the usual 'Hello World!' program and the second one testing nested loops to increment count to 64 and print the result (should be '@'):