[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

[FWP] Re: Turing machine simulator



In article <20001208215316.A2020@puffinry.freeserve.co.uk>,
	robin@kitsite.com writes:
> 
> A1A1R
> A0A0R
> A B L
> B1B0L
> B0C1L
> B C1L
> C1C1L
> C0C0L
> C ! R
> 
> 
> I was aiming for brevity, and it *is* 58 characters shorter than
> Mark's version. I'm sure it could be compressed more, with some
> thought.
> 
>  .robin.
> 
> 
> #!/usr/local/bin/perl -p0777
> y= =\0=;s=(.)(.)(.)(.)(.)="s/(.)\Q$1\E\b\Q$2\E/".($5eq"R"?"\${1}$4$3\b":
> "$3\b\${1}$4")."/&&die;"=eg;$t=$_;$_="A\b".shift;{$_="\0$_\0";eval$t;
> $@||die;/!\ch/&&last;redo}
> 
Inspired by this, spifff and me came up with
(first line is start tape, error if it stops with a letter in the output):

$/=$_;$_=<>;$;="(.)"x4;s/^.*/\$_='A$&';s|!||while s|^ *| |%s| *\$| |/;s/$;R/+s|$1$2|$4$3|/g;s/$;L/+s|(.)$1$2|$3\${1}$4|/g;eval;print

==== Want to unsubscribe from Fun With Perl?  Well, if you insist...
==== Send email to <fwp-request@technofile.org> with message _body_
====   unsubscribe