C
Carl Banks
Michael said:Bernhard Herzog wrote:
....
a Turing Machine in one line plus assignments - nice! Turns out that pypy is more
verbose than strictly necessary ;-)
...
BTW, I realized that it is indeed possible for a LC to maintain its own state
without being passed an external mutable. The trick is to use itertools.repeat
to return the same mutable object on each iteration.
Pay attention, chief. I suggested this days ago to remove duplicates
from a list.
from itertools import *
[ x for (x,s) in izip(iterable,repeat(set()))
if (x not in s,s.add(x))[0] ]
There is a way to even avoid repeat if you're feeling EVIL.
[ x for x in iterable if x not in locals()['_[1]'].__self__ ]
Turning this into a turing machine is left as an exercise. The recipe
in effect:
http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/204297