Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@willhbr
Created June 6, 2016 06:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save willhbr/333964c5363301d555cde0450cc12506 to your computer and use it in GitHub Desktop.
Save willhbr/333964c5363301d555cde0450cc12506 to your computer and use it in GitHub Desktop.
Meh
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)
})
@moskyb
Copy link

moskyb commented Jun 6, 2016

Will why would you make this

@willhbr
Copy link
Author

willhbr commented Jun 6, 2016

Entirely Logan's fault.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment