Tetris In 140 Bytes

Is it possible to write a JavaScript program in no more than a tweet‘s length? A website called 140byt.es says it is. The site has an implementation of “almost” Tetris to prove it. Its title is “Binary Tetris“, and it only has two types of block and there’s no rotate, but it works. The blocks fall down the screen and you steer them into place. You can try it out by playing the demo.

Of course the real fun is in figuring out how this Tetris In 140 Bytes works. The code includes the main logic to move blocks, detect collision, assign new blocks, remove full lines and render the layout are included (keyboard controls and the final rendering are excluded).


function(a,b,c,d,e){return d+=c,
e=a|b<<d,d<0|a&b<<d&&(a=e=
parseInt((a|b<<c).toString(d=32)
.replace(/v/,""),d),b=new Date%2?1:3),
[a,b,d,e]}

140byt.es is a tweet-sized, fork-to-play, community-curated collection of JavaScript that gives you help on figuring out how this kind of tiny JavaScript code can be made. There you will find some interesting tips on how to save space while writing JavaScript.

If your bored how about writing your own 140 character challenge?

2 Comments

  1. MIT Huge Tetris Hack « Tomi Engdahl’s ePanorama blog says:

    [...] Huge Tetris Hack I have earlier written about a tiny Tetris. Not is time for a big Tetris. At MIT, fun is accomplished with architecture. Hackers turn MIT [...]

    Reply
  2. Tomi Engdahl says:

    Tetris in 446 Bytes
    http://hackaday.com/2016/10/06/tetris-in-446-bytes/

    You want a Tetris that’ll fit inside the master boot record of a disk. You want Tetris as an operating system. You want TetrOS.

    Or maybe you don’t, but it’s a fantastic piece of work, and we love tiny demos

    TetrOS
    Tetris that fits into the boot sector.
    https://github.com/daniel-e/tetros

    TetrOS is a small feature rich Tetris clone which is written in Assembly. It fits completely into a 512 byte boot sector as it requires only 446 bytes (which is the maximum allowed size of the first stage boot loader in the master boot record (MBR) of a drive) and is executed during the boot sequence before any operating system is loaded. Actually, it does not need any existing operating system. TetrOS is an operating system, hence the suffix OS in its name.

    Reply

Leave a Comment

Your email address will not be published. Required fields are marked *

*

*