4 ms·
Brainfuck in one line of Python
- benatkin 15y agoThat isn't the normal way of measuring the length of code in code golfing contests. It's number of normal-sized lines, for some measurement of normal that is less than 1400 characters. Pretty neat, though; just a misleading title.
- rcthompson 15y agoMaybe "in one Python statement" would be more appropriate.
- mahmud 15y agoEvery Lisp program can be rewritten to be just "one expression" `(progn ,@program) What have we achieved here?
- tjoff 15y agoI think the first paragraph explained it quite well. Whether or not the feat itself is impressive or not I don't really know but the reason for the quest was motivated.
- mahmud 15y agoMy point was that "one-line" is a faulty criterion for measuring compactness if we allow for arbitrarily long lines: or "long cat is long" considered harmful.
- nknight 15y agoI'm guessing you don't deal with Python much. Python actively discourages this sort of thing, it's actually hard to create obfuscated code of the kind you see in most other languages. That this was even possible surprised me somewhat, that he actually figured it out I find quite impressive.
- mahmud 15y agoFair point, and the magnitude of this feat was not lost on me. I was just speaking in general, we need a better metric for one-linerness than s/\n//g.
- _delirium 15y agoAnd for our next trick, Python in one line of Brainfuck...
- pak 15y agoAny program can be called a "one liner" if you just strip newlines and don't limit the line length.
- gliptic 15y agoNot in Python.
- steve-howard 15y agoIt's generally accepted that a semicolon (in most languages) means two lines no matter how the spacing goes. In Python, it's particularly tricky to have a complex program evaluate to one statement because of limitations like no assignments in expressions. It's true, though, that this is basically the same as writing Lisp in Python.
- deleted 15y ago[deleted]
- vidarh 15y agoI must admit I was disappointed - v2 of the original AmigaOS Brainfuck compiler is a 240 bytes binary, and the C interpreter is 1047 bytes of unobfuscated C source. 1400+ bytes of tightly packed Python just isn't in the same class.
- Goladus 15y agoThe goal wasn't "tightly packed" the goal was "one line." In Python that means, essentially, one expression. That's what makes it a stunt.
- vidarh 15y agoMy point with mentioning "tightly packed" was that if you'd tried to make the C version small, you'd come out with something much tinier than the 1047 bytes I mentioned. I see he's set himself a very different goal, which is fine but not that interesting to those of us that aren't Python programmers, I guess. What disappointed me was clicking through from a headline that seemed to indicate it'd be a tiny implementation, when it's in fact rather bloated.
- ricardobeat 15y agoIn this case "one line" doesn't mean much. You could have a 1mb file in one line. Nowadays a "line" is between 80-140 characters.
- rplnt 15y agoYou are not entirely right. In python, one line means something as it is only one statement (as mentioned above). Author is also strict about not using eval -- with eval you could snuck multiple lines into one line (using \n in the evaluated string).
- worldimperator 15y agoLast time when I used python I could separate statements with a semicolon and put as many as i want in a line. Did that change ? ;-)
- DanielRibeiro 15y agoyou can't parse any non-regular language on any given computer It is nice how the author completely ignored LALR parsers[1], peg parsers[2], and so on. [1] http://en.wikipedia.org/wiki/LALR_parser http://en.wikipedia.org/wiki/LALR_parser [2] http://en.wikipedia.org/wiki/Parsing_expression_grammar http://en.wikipedia.org/wiki/Parsing_expression_grammar
- deleted 15y ago[deleted]
- thurn 15y agoYou can only imperfectly emulate anything more than a regular language in a finite reality (since a pushdown automaton has an infinite stack). A PC is just a big DFA.
- Dylan16807 15y agoSo how long would it be if you used a better python interpreter with tail calls?
- shubsengupta 15y agoI'm still appalled at the fact that the term 'brainfuck' is used in a Princeton website.
- Dylan16807 15y agoWhy? It is the name of the language.
- pak 15y agoLots of people can put things on URLs under princeton.edu, or the domains of most universities. In this case, note the ~username in the URL--this is the personal page of a graduate student. Usually universities do not censor pages of their students. I do agree, though, that it would be surprising to see this on a departmental page or anything else owned by a PR team.
- deleted 15y ago[deleted]