View Full Version : A 'Tetris' JavaScript game in only 140 Bytes

02-28-2012, 07:38 AM
Using a JavaScript function shorter than a tweet's length!


An user from a website called 140byt.es managed to implement a JavaScript version of Tetris called 'Binary Tetris' using a function with less than 140 characters.

Well, this is a surely interesting JavaScript approach. A website, called 140byt.es (http://140byt.es/) says it's possible to write a program in no more than a tweet's length.


This is a Tetris variant with only two types of blocks, called "Binary Tetris".There is no rotation, but it the same basic idea.

The complete function is:

function(a,b,c,d,e){return d+=c,
.replace(/v/,""),d),b=new Date%2?1:3),

Of course the fun for the reader is to work out how it works. To do this you need to know that the function doesn't include the display routine or the user interaction. You also need to know some tricks of the trade. In particular, if you are wondering what the Date object is doing in there, it's a cheap way to get random numbers.

Yes, there are a few things to note, like the fact that the 'game' is pretty limited, and some people says it takes a few more bytes in order to call the routines. It also seems they aren't counting the number of libraries required to operate it, but it's a nice implementation that makes you remember the good old programming days.

And, if you're bored, you can always participate at the 140byt.es website and go for a challenge.

You can check the game's demo and its source code at the websites below.

SOURCE CODE: http://jsbin.com/egiqul/49

NEWS SOURCE: Tetris in 140 bytes (via) i-Programmer (http://www.i-programmer.info/news/167-javascript/3799-tetris-in-140-bytes.html)

Our thanks to 'Gauss' for a neat news story!