News for hackers. Stuff that matters.
Re:A turing machine in 133 bytes of javascript by AndreasT on Monday November 28, 2011 @06:53AM (#3285508)
$ uglifyjs function tm(I,t,e,s,i,c,k) {i=0;while(s!=e){c=t[i];k=(c)?I[s][c]:I[s].B;if(!k)return false;t.splice(i,1,k.w);i+=k.m;s=k.n;}return t;} function tm(a,b,c,d,e,f,g){e=0;while(d!=c){f=b[e],g=f?a[d][f]:a[d].B;if(!g)return!1;b.splice(e,1,g.w),e+=g.m,d=g.n}return b}
Re:A turing machine in 133 bytes of javascript by Swizec on Monday November 28, 2011 @07:05AM (#3285534)
So it's two characters shorter?

I left the two ;} because my syntax highlighter was yelling at me that I'm doing something ugly and I was inside the 140B limit anyway.

Re:A turing machine in 133 bytes of javascript by darklajid on Monday November 28, 2011 @07:14AM (#3285549)
No, not just two.

It stripped the space before the first { and between the "return" and "false".

False is represented as !1.

"(c)?foo:bar" is replaced by "c?foo:bar". Plus - semicolons are removed as you noticed.

But - really.. It's ugly enough as it is :)

Re:A turing machine in 133 bytes of javascript by jedschmidt on Monday November 28, 2011 @09:19AM (#3285926)
I'm sure there's room left that the 140byt.es folks will find, but off the bat:

    e=0;while(d!=c)
    for(e=0;d!=c;)
Re:A turing machine in 133 bytes of javascript by Swizec on Monday November 28, 2011 @11:56AM (#3286588)
This is the shortest solution somebody has come up with, 79 characters.

function(a,b,c,d,e){for(e=0;d<c;)with(a[d][b[e]||"B"])b[e]=w,e+=m,d=n;return b}

Source: https://gist.github.com/1400509

Re:A turing machine in 133 bytes of javascript by friggeri on Monday November 28, 2011 @11:04AM (#3286381)
Got it down to 118 bytes ;)

    function tm(I,t,e,s,i,c,k){for(i=0;s!=e;i+=k.m,s=k.n){k=I[s][(c=t[i])||"B"];if(!k)return k;t.splice(i,1,k.w)}return t}
You could actually save one more byte by changing the name of the function, but that would be cheating, right ? ;-)

Edit, Refined it to get to 110:

    function tm(I,t,e,s,i,c,k){for(i=0;s!=e;t[i]=k.w,i+=k.m,s=k.n){k=I[s][(c=t[i])||"B"];if(!k)return k;}return t}
Re:A turing machine in 133 bytes of javascript by binarymax on Monday November 28, 2011 @07:20AM (#3285560)
Looks great! If trimming javascript down to its pants is keeping you up at night, come and join us other golfers at http://140byt.es
Re:A turing machine in 133 bytes of javascript by bulte-rs on Monday November 28, 2011 @07:21AM (#3285564)
The only thing more awesome than this would be a JS environment written for the turing machine which is able to run itself.
Re:A turing machine in 133 bytes of javascript by jonbro on Monday November 28, 2011 @07:39AM (#3285617)
The last time I was working on one of these, I discovered the phrase http://en.wikipedia.org/wiki/Turing_tarpit

Not that these are all a waste of time or anything, you just need to remember not to take them too far.

Re:A turing machine in 133 bytes of javascript by Swizec on Monday November 28, 2011 @08:02AM (#3285664)
A turing tarpit is a whole different beast. Brainfuck and whitespace are examples of a turing tarpit.

This is just codegolfing.

Re:A turing machine in 133 bytes of javascript by amouat on Monday November 28, 2011 @06:53AM (#3285506)
Should have called it l33t machine