-
-
Save pasberth/4334180 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# coding: utf-8 | |
@eip = 0 | |
@before_bracket = 0 | |
@is_skip = false | |
@memory = Array.new(30000) { 0 } | |
@pointer = 0 | |
# http://ideone.com/3Ev4dC このプログラム動いたっ | |
code = ">>>>>>>>>>>>+++[-<+++++>]<[-<<<<<<<<<<<+++++>+++++++>+>++++++++++++++>+++++++++++>+++++++++>++>++++++++++++>++++++++++++++>++++++++++>+++++++>]<++++++<---<----<+++++<++<---<++<++++++<-----<----<---.>.+++++++..+++.>.>.>.<+.>>.<<-.>++++++++++++.<+.>>.<<-.>------------.<+.>>+.>.<<<-.>>>>.<<<<+.>>-.<<.>>++++++.<<.>>-------.<<.>>++.<<<.>+++++++++++.>>>>++++.<<<-------.<+.>+++++.>>>.<<<<<.<<-.>.----------.-.+.-.---.++++++.>.<<-----.>++++++++.-.----.+++++.++++++.---.>.>>>>>>.>.<.<--------.>.<++++.>.<<<<+++++++.>>+.<<<<.>-----.>--------.++++.<.>----.++++++++++.<.>----------.>>>-.<<<<.>+.>++++++++.<<.>-..<.>+.>------.<<<.<<+.>---------.--------.>>>>>>>>>.<<<<<<<<.>+++.>>------.>>>>.<<<<<<.>>+.>>>>.<<<<<<.>>-.<++++++.<.>>.<----------.<.>>.>>---------.<<<<<.>+++++++++.>------------.-------------.<-.>---.>>>>>++.<<<<<<++.>>>>>>.+++.<<<<<<-.>++++++.>>>--.<<<<-.>.---.<-.>>>>+++.<<<--------.<<.<<.>>>>------.<<<++++.>>>>>>>---------.>+++.<-.<<<<+++++++++++++.<<.>>>>>>--.>++++++.<<<<<<<<<+++++.>++++++++++.---.-----------.>>>>>.<<<<." | |
def get_elem | |
@memory[@pointer] | |
end | |
def brainfuck command | |
if @is_skip | |
if command == "]" | |
@is_skip = false | |
end | |
return | |
end | |
case command | |
when "." | |
print get_elem.chr | |
when "+" | |
@memory[@pointer] += 1 | |
when "-" | |
@memory[@pointer] -= 1 | |
when ">" | |
@pointer += 1 | |
when "<" | |
@pointer -= 1 | |
when "[" | |
if get_elem == 0 | |
@is_skip = true | |
else | |
@before_bracket = @eip | |
end | |
when "]" | |
if get_elem != 0 | |
@eip = @before_bracket | |
end | |
end | |
end | |
while @eip < code.length | |
ch = code[@eip] | |
brainfuck(ch) | |
@eip += 1 | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment