Results 1 to 9 of 9

Thread: Awesome trick! The powers of Javascript!

  1. #1

    Talking Awesome trick! The powers of Javascript!

    I saw this a while back on another website and... I simply don't understand how it's possible to do this with such a short bit of Javascript.

    Create a new plain text file, copy & paste in the following code, then save it with a .html file extension.

    Ha ha -- this takes me back to the days of 8-bit computing when, instead of using the Internet to download a file, or even a cover-tape/disk, computer magazines would print the source code of programs so you could type them in yourself at home. I remember there being a section called "Ten Liners" where programmers would try to cram as much as they could into ten 255-character lines of code, with often impressive results. Simple shoot-em-ups were always popular.

    Can anyone work out what the code does without running it? (I doubt it!) And how is it possible to write an algorithm like this with so little code?! Are there built-in Javascript functions that are being utilised somehow...?

    Code:
    <html><body><script> for(B=i=y=u=b=i=5-5,x=10,I=[],l=[];B++<304;I[B-1]=B%x?B/x%x<2|B%x<2?7:B/x&4?0:l[i++]="[email protected]@TSb~?A6J57IKJT576,+-48HLSUmgukgg OJNMLK  IDHGFE".charCodeAt(y++)-64:7);function X(c,h,e,s){c^=8;for(var o,S,C,A,R,T,G,d=e&&X(c,0)>1e4,n,N=-1e8,O=20,K=78-h<<9;++O<99;)if((o=I[T=O])&&(G=o^c)<7){A=G--&2?8:4;C=o-9?l[61+G]:49;do if(!(R=I[T+=l[C]])&&!!G|A<3||(R+1^c)>9&&G|A>2){if(!(R-2&7))return K;n=G|(c?T>29:T<91)?o:6^c;S=(R&&l[R&7|32]*2-h-G)+(n-o?110:!G&&(A<2)+1);if(e>h||1<e&e==h&&S>2|d){I[T]=n;I[O]=0;S-=X(c,h+1,e,S-N);if(!(h||e-1|B-O|T-b|S<-1e4))return W(),c&&setTimeout("X(8,0,2),X(8,0,1)",75);I[O]=o;I[T]=R}if(S>N||!h&S==N&&Math.random()<.5)if(N=S,e>1)if(h?s-S<0:(B=O,b=T,0))break}while(!R&G>2||(T=O,(G||A>2|(c?O>78:O<41)&!R)&&++C*--A))}return-K+768<N|d&&N}function W(){i="<table>";for(u=18;u<99;document.body.innerHTML=i+=++u%x-9?"<th width=60 height=60 onclick='I[b="+u+"]>8?W():X(0,0,1)'style='font-size:50px'bgcolor=#"+(u-B?u*.9&1||9:"d")+"0f0e0>&#"+(I[u]?9808+l[67+I[u]]:160):u++&&"<tr>")B=b}W() </script></body></html>
    Pretty cool, huh?

  2. #2

    Default



    Quote Originally Posted by tiny View Post
    ... Can anyone work out what the code does without running it? (I doubt it!) ...
    Will it transform the internet into a place full of love, maturity, and tolerance?

  3. #3

    Default



    Quote Originally Posted by ShadowHare View Post
    Will it transform the internet into a place full of love, maturity, and tolerance?
    It's a cool script, but not that cool! You'd need C++ for that...

    Why not run it and see for yourself...? ;-)

  4. #4

    Default



    Quote Originally Posted by tiny View Post
    Can anyone work out what the code does without running it? (I doubt it!) And how is it possible to write an algorithm like this with so little code?! Are there built-in Javascript functions that are being utilised somehow...?
    Mind = Blown. xD

    About all I could tell from the code was that it would write a page with tables and text somewhere in there. >.>



    Quote Originally Posted by ShadowHare View Post
    Will it transform the internet into a place full of love, maturity, and tolerance?
    Impossibru.

  5. #5

    Default

    Very cool, I'm not terribly surprised, it's been minified to obscurity, but even if it wasn't it would likely look like a beautiful, efficient piece of code. Thanks for sharing!

  6. #6

    Default

    Wow... I spent about three minutes staring at the code before my curiosity got the better of me, and I can honestly say I doubt I would have even remotely come to the conclusion that that little bit of code, as minified and obfuscated as it is, would give me a completely working game of Chess.

    Edit: Now that I look closer, that is a lot more code than I thought it was...

    This is what it looks like when opened in Dragonfly. (It has a built-in beautifier.)
    http://i.imgur.com/kIufGYE.png

    What I've deduced so far:
    "I" is a giant array that contains the values for the pieces on the board on their current locations, which calls the function "W()" that redraws the table with new onclick events that are only positioned in places that would result in the mod of the current board location by the current piece type value minus nine equaling to something greater than zero. This is what gives the board rules based on the type of piece's value from the I array. (With the exception of pawns which are denoted by 7s in the array). The mod to the odd or even makes the table elements the two separate colors, and b would be assigned the type of piece you are looking at in each iteration of the loop. The I array is called according to the values that are written out to the page during the initial rendering process...

    So that's one mystery solved. I don't really feel like figuring out how the AI works though...
    Last edited by thingywhat; 20-Feb-2013 at 05:13.

  7. #7

    Default

    Huh... I'm impressed you managed to figure all of that out!

    But it's the AI that puzzles me! I can remember in the mid-1980s getting chess simulators, and the idea of a computer being able to beat a human just seemed amazing! I remember thinking about how the AI could be programmed and it seemed an insane task to analyse every possible piece and how it could move and develop a strategy. Ha! I think I had to wait about 30 seconds after each go for my super-fast 4MHz CPU (ha ha -- 0.004GHz!) to make its move in "easy" mode!

    But reducing this to a handful of lines of Javascript (or one very long one!) just blows my mind!

  8. #8
    TheArtist

    Default

    I run no script on my browser, makes the interweb a much nice place to be, also why is adisc on https, costs way more, and it's not like anything is private, pointless?

  9. #9

    Default



    Quote Originally Posted by tiny View Post
    Huh... I'm impressed you managed to figure all of that out!

    But it's the AI that puzzles me! I can remember in the mid-1980s getting chess simulators, and the idea of a computer being able to beat a human just seemed amazing! I remember thinking about how the AI could be programmed and it seemed an insane task to analyse every possible piece and how it could move and develop a strategy. Ha! I think I had to wait about 30 seconds after each go for my super-fast 4MHz CPU (ha ha -- 0.004GHz!) to make its move in "easy" mode!

    But reducing this to a handful of lines of Javascript (or one very long one!) just blows my mind!
    Well, it would really help if it wasn't minified. I doubt whoever wrote this wrote it as we see it right now, but rather piped it through a minifier.

    Does anyone have any idea where the original source is?

Similar Threads

  1. Replies: 9
    Last Post: 07-Sep-2011, 15:44

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
ADISC.org - the Adult Baby / Diaper Lover / Incontinence Support Community.
ADISC.org is designed to be viewed in Firefox, with a resolution of at least 1280 x 1024.