Created
June 6, 2016 06:11
-
-
Save willhbr/333964c5363301d555cde0450cc12506 to your computer and use it in GitHub Desktop.
Meh
This file contains 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
read("", :program, { | |
def(:program_length, send(program, :length)) | |
def(:program_location, 0) | |
def(:input, (1, 2, 3, 4)) | |
def(:input_location, 0) | |
def(:program_char, { | |
send(program, :substring, program_location, +(program_location, 1)) | |
}) | |
def(:get_input, { | |
def(:input_location, +(input_location, 1)) | |
send(input, :get, -(input_location, 1)) | |
}) | |
def(:pointer, 0) | |
def(:method_missing, :missing_name, { 0 }) | |
def(:inc_pointer, :amount, { | |
def(:pointer, +(pointer, amount)) | |
}) | |
def(:current, { def(+(:stack_, pointer)) }) | |
def(:incr, :amount, { | |
def(+(:stack_, pointer), +(current, amount)) | |
}) | |
def(:set, :amount, { | |
def(+(:stack_, pointer), amount) | |
}) | |
def(:output, ()) | |
while(<(program_location, program_length), { | |
def(:char, program_char()) | |
if(=(char, ">"), { inc_pointer(1) }) | |
if(=(char, "<"), { inc_pointer(-1) }) | |
if(=(char, "+"), { incr(1) }) | |
if(=(char, "-"), { incr(-1) }) | |
if(=(char, "."), { send(output, :add, current) }) | |
if(=(char, ","), { set(get_input()) }) | |
if(=(char, "["), { | |
if(=(current, 0), { | |
def(:program_location, +(program_location, 1)) | |
def(:br_count, 1) | |
while(>(br_count, 0), { | |
def(:char, program_char()) | |
if(=(char, "["), { def(:br_count, +(br_count, 1)) }) | |
if(=(char, "]"), { def(:br_count, -(br_count, 1)) }) | |
def(:program_location, +(program_location, 1)) | |
}) | |
}) | |
}) | |
if(=(char, "]"), { | |
if(=(current, 0), {}, { | |
def(:br_count, 1) | |
def(:program_location, -(program_location, 1)) | |
while(>(br_count, 0), { | |
def(:char, program_char()) | |
if(=(char, "["), { def(:br_count, -(br_count, 1)) }) | |
if(=(char, "]"), { def(:br_count, +(br_count, 1)) }) | |
def(:program_location, -(program_location, 1)) | |
}) | |
}) | |
}) | |
def(:program_location, +(program_location, 1)) | |
}) | |
def(:string, "") | |
repeat(send(output, :size), :index, { | |
def(:string, +(string, send(str(send(output, :get, index)), :get, 0))) | |
}) | |
print(string) | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Will why would you make this