Quantcast
Viewing latest article 4
Browse Latest Browse All 17

Answer by Natte for Write a Stack Exchange compliant brainfuck explainer

Ruby, 118 bytes

c,*a=*$<print" "*l=4,cc.scan(/[^+-.\[\]<>\n]+|./){puts" "*l+$&+" "*(c.size+4-l+=$&.size)+a["><+-.,[]".index($&)||8]}

Try it online!

Explanation

c,*a=*$<                                 # assign 'c' to first line and 'a' to the rest of inputprint" "*l=4,c                           # output code and assign 'l' to 4 at the same timec.scan(/[^+-.\[\]<>\n]+|./)              # for every match:{puts" "*l+$&+" "*(c.size+4-l+=$&.size)+ # output the padded match, update 'l' to keep track of the spacesa["><+-.,[]".index($&)||8]}              # output the correct explanation

inspiration taken from lonelyelk


Viewing latest article 4
Browse Latest Browse All 17

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>