elm-city-craftworks/turing_tarpit — Issue #4: It is way too clean code for the spirit of Brainfuck!
Author: eregon
Created: 2012-01-18 17:28:24+00:00
State: open

"Category set to Joke"

I believe the code is not respecting the "philosophy of Brainfuck" and more particularly the idea of the interpreter written in the least number of bytes.

> French (because Wikipedia en is ... you know): "L'objectif de Müller était de créer un langage de programmation simple, destiné à fonctionner sur une machine de Turing, et dont le compilateur aurait la taille la plus réduite possible"

So here is mine, in 40 lines, which has most features (handle infinite tape, with negative numbers, skip ahead conditions met the first time, and handle basic debugging) and is actually thrice faster (but yet 100x slower than C) (quick numbers, don't believe me):

```ruby
require 'io/console'

b = ARGF.read.chars.select { |c| '<>+-[].,'.include? c }.join
m, loops, i, pos = [], [], 0, 0
while c = b[pos]
if i.abs >= (s = m.size/2)
m = m[0...s] + [0,0]*(i.abs-s+1) + m[s..-1]
end

puts "i=#{i} #{m}" if $DEBUG
case c
when '>'
i += 1
when '<'
i -= 1
when '+'
m[i] += 1
when '-'
m[i] -= 1
when '.'
putc m[i]
gets if $DEBUG
when ','
m[i] = STDIN.getch.bytes.first
when '['
if m[i] == 0
c = 1
begin
pos = b.index(/\]|\[/, pos+1)
c += b[pos] == ']' ? -1 : 1
end until c == 0
else
loops << pos
end
when ']'
_ = loops.pop
pos = _ - 1 if m[i] != 0
end
pos += 1
end
```

and in the original spirit, in 207 bytes (minimal feature set):

```ruby
b=ARGF.read;m,i,p,l=[0]*100,0,0,[]
while c=b[p];case c;when'>';i+=1;when'<';i-=1;when'+';m[i]+=1;when'-';m[i]-=1;when'.'
putc m[i];when',';m[i]=getc;when'[';l<>+++ + [->>>++ < < ++++[-> ++<]<] >>[-<+ + <+<+> > >] +++[-<+ + + >]<.<. [ - >
+ < ] > + + + . + + + . < + +[ - > + + + <] > + .
> + + + [ - < < + + + [ - > - - < ] >>] < + . <
< . [ - < + >>++< ]>++.> >++++[ - < + + + > ]<+.> >[->+<< < --> >
] < < - . > > > [ - < +<<+>>> ] < < < . >++ [ - < +
+ > ] < + . > > [ - > + < < < -> > ] < < .< < +
++[-< +++>]< +.>>>-- - .>>>[-< <<+>>> ] < < < .<[-- <+ > ] < . [-<->] < + .
```