Hacker News new | past | comments | ask | show | jobs | submit login
JavaScript was Brainfuck all along (medium.com/djordje.ungar)
69 points by artbit 7 months ago | hide | past | favorite | 13 comments




Hah! That's awesome. I wasn't aware of it.

But yeah, it's not a new idea really. Even my original article was written, over a decade ago: https://blog.djordjeungar.com/post/2011-09-13-obscure-javasc...


And then there was that time some people used jsfuck to do xss on Ebay:

https://arstechnica.com/information-technology/2016/02/ebay-...


Cloudflare uses it for some of their challenges.


JavaScript type coercion allows for some really obscure transformations, that make it look like BrainFuck.


I have used this on some coding challenges when you try to get the shortest answer or oneliner.


Hard mode: write a nontrivial program the intersection of javascript and brainfuck (no characters except []+-,.<>), which does the same thing in both languages.


Brainfuck interpreters just ignore the characters in the file that aren't those particular Brainfuck operators, treating them as comments. So, you could just write a Brainfuck interpreter in JavaScript that interprets a string literal, then write the Brainfuck program as a string literal. You'd still have to write the JavaScript BF interpreter so that everything that isn't the string literal has no observable effect when interpreted by a BF interpreter.


put the interpreter into a function placed in an array at the beginning. use an array constructor for this and your whole interpreter is now wrapped by a bf loop at the start of the program. Which bf will immediately skip tecause the initial cell will be 0. Then index into an array to get the first item. Another loop on the initial cell. Skipped. Then pass the bf source to the function. No brainfuck commands are needed for this.

<pre><code> [ function(src){ // interpreter goes here } ][[]]("brainfuck source goes here"); </code></pre>So your interpreter could be anything you want and it won't conflict with any other bf code as long as you keep your square brackets matched up (this is easy to do in js).

The rest is, of course, an exercise left to the reader.


That's easy mode


Doesn't TypeScript let you build things like this right in the static types?


The design and impl of Brainfuck represents more thought, effort, esthetics, and clarity of purpose than the initial JavaScript.


Haha JavaScript bad, amirite fellow codemonkeys?!




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: