
Brainfuck in one line of Python - JJMalina
http://www.cs.princeton.edu/~ynaamad/misc/bf.htm
======
_delirium
And for our next trick, Python in one line of Brainfuck...

------
vidarh
I 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
The goal wasn't "tightly packed" the goal was "one line."

In Python that means, essentially, one expression. That's what makes it a
stunt.

~~~
ricardobeat
In 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
You 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
Last 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 ? ;-)

~~~
rplnt
I'm not sure you can write function definitions, (nested) loops and other
things that rely on indentation in single line using semicolons. At least I
never managed to do that.

~~~
worldimperator
You can do it with lambdas, but it's going to be absurdly ugly:
[http://blog.sigfpe.com/2008/09/on-writing-python-one-
liners....](http://blog.sigfpe.com/2008/09/on-writing-python-one-liners.html)

------
benatkin
That 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
Maybe "in one Python statement" would be more appropriate.

~~~
mahmud
Every Lisp program can be rewritten to be just "one expression"

    
    
      `(progn ,@program)
    

What have we achieved here?

~~~
tjoff
I 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
My 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
I'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
Fair 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.

------
DanielRibeiro
_you 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>

[2] <http://en.wikipedia.org/wiki/Parsing_expression_grammar>

~~~
thurn
You 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.

------
pak
Any program can be called a "one liner" if you just strip newlines and don't
limit the line length.

~~~
steve-howard
It'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.

------
Dylan16807
So how long would it be if you used a better python interpreter with tail
calls?

------
shubsengupta
I'm still appalled at the fact that the term 'brainfuck' is used in a
Princeton website.

~~~
pak
Lots 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.

