lib/r-fxxk.rb in r-fxxk-0.2.0 vs lib/r-fxxk.rb in r-fxxk-0.3.0
- old
+ new
@@ -39,10 +39,14 @@
cur = src.index(reg, cur) + matches[1].length
end
dst
end
+ def hello_world
+ translate(BrainFuck, '>+++++++++[<++++++++>-]<.>+++++++[<++++>-]<+.+++++++..+++.[-]>++++++++[<++++>-]<.>+++++++++++[<+++++>-]<.>++++++++[<+++>-]<.+++.------.--------.[-]>++++++++[<++++>-]<+.[-]++++++++++.')
+ end
+
def fuck(src)
src = compile(src)
ptr = 0
cur = 0
cell = Array.new(3000) { 0 }
@@ -62,12 +66,31 @@
cell[ptr] -= 1
when :put
output << cell[ptr].chr
when :get
when :opn
- next_cur = src.index(self.class.bf_mapping[:cls], cur) + 1 if cell[ptr] == 0
+ if cell[ptr] == 0
+ open_count = 1
+ buf_cur = cur
+ while open_count > 0
+ open_count.times do
+ next_cur = src.index(self.class.bf_mapping[:cls], buf_cur)
+ open_count = src[buf_cur+1..next_cur].count(self.class.bf_mapping[:opn])
+ buf_cur = next_cur
+ end
+ end
+ next_cur = next_cur + 1
+ end
when :cls
- next_cur = src.rindex(self.class.bf_mapping[:opn], cur)
+ close_count = 1
+ buf_cur = cur
+ while close_count > 0
+ close_count.times do
+ next_cur = src.rindex(self.class.bf_mapping[:opn], buf_cur)
+ close_count = src[next_cur..buf_cur-1].count(self.class.bf_mapping[:cls])
+ buf_cur = next_cur
+ end
+ end
end
cur = next_cur || src.index(reg, cur) + matches[1].length
end
output.join
end