list = Array.new(1000){0} script = ARGF.readlines.map{|x|x.chomp}.join puts script ptr = 0 pos = 0 parents = [] loop do case script[pos] when '>'.sum #increment pointer ptr += 1 pos += 1 when '<'.sum #decrement pointer ptr -= 1 pos += 1 when '+'.sum #increment list of pointer list[ptr] += 1 pos += 1 when '-'.sum #decrement list of pointer list[ptr] -= 1 pos += 1 when '.'.sum #putchar print list[ptr].chr pos += 1 when ','.sum #getchar list[ptr] = STDIN.getc pos += 1 when '['.sum #jump to next ] if list of pointer is 0 if list[ptr] == 0 if pair = lambda do |curpos| inner = 0 while x = script[curpos+=1] case x when ']'.sum if inner > 0 inner -= 1 else return curpos end when '['.sum inner += 1 end end nil end.call(pos) pos = pair + 1 else raise "Missmatched open parenthes" end else parents.push pos pos += 1 end when ']'.sum #jump to previews [ raise "Missmatched close parenthes" if parents.empty? pos = parents.pop when nil #end script exit else warn "unkown charctor:" + script[pos,1] pos += 1 end #print script[pos].chr end