Anonymous user
Execute Brain****/Ruby: Difference between revisions
m
simplify a bit
m (Categorization now in master page) |
m (simplify a bit) |
||
Line 12:
def read_program
jumpback_table = {}
@program.each_char.each_with_index do |char, idx|
case char
when "[" then jump_to.push(idx)
when "]"
end
end
Line 49 ⟶ 44:
print "\t#{dc},#{@d[dc]}\t" if $DEBUG
print @d[dc].chr
when ?,
@d[dc] = $stdin.getc
print "\t#{dc},#{@d[dc]}" if $DEBUG
when ?[
if @d[dc] == 0
pc = @jumpback_table.invert[pc]
p " #{[pc,@program[pc].chr].inspect}" if $DEBUG
end
when ?]
if @d[dc] != 0
pc = @jumpback_table[pc]
Line 77 ⟶ 72:
bf.run
# use nested loop to increment count to 64 and print (should be '@')
# followed by a newline
Output:
|