Follow Slashdot stories on Twitter

 



Forgot your password?
typodupeerror
×
Programming Build Games Idle News

Tetris In 140 Bytes 215

mikejuk writes "Is it possible to write a JavaScript program in no more than a tweet's length? A website called 140byt.es says it is and has an implementation of Tetris to prove it. Ok, it only has two types of block — hence its title "Binary Tetris" — 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 it works and there is lots of help on the site — so if you're bored how about the 140 character challenge?"
This discussion has been archived. No new comments can be posted.

Tetris In 140 Bytes

Comments Filter:
  • by Anonymous Coward

    Binary Tetris?

    http://a.fsdn.com/sd/topics/programming_64.png

  • Nostalgia ... (Score:5, Insightful)

    by WrongSizeGlass ( 838941 ) on Sunday February 19, 2012 @10:30AM (#39092575)
    It reminds me of the old days when code was efficient and had to fit onto small discs and into limited RAM and/or ROM. The original Mac ROMs were 128k, and all the apps had to run in 128k of RAM. It was amazing what could be done when it just had to fit.
    • Re:Nostalgia ... (Score:5, Interesting)

      by arth1 ( 260657 ) on Sunday February 19, 2012 @10:51AM (#39092701) Homepage Journal

      It reminds me of the old days when code was efficient and had to fit onto small discs and into limited RAM and/or ROM. The original Mac ROMs were 128k, and all the apps had to run in 128k of RAM. It was amazing what could be done when it just had to fit.

      Get off my lawn. The ZX-80 and -81 had 1 kB, and there were plenty of games for them. Then there were other computers, all with limited memory.
      I'm sure there are lots of people here except yours truly who have written a variant of SNAKE.

      • Comment removed (Score:5, Interesting)

        by account_deleted ( 4530225 ) on Sunday February 19, 2012 @05:24PM (#39095281)
        Comment removed based on user account deletion
      • Re:Nostalgia ... (Score:4, Interesting)

        by Zadaz ( 950521 ) on Monday February 20, 2012 @01:15AM (#39097421)

        Nibble magazine (an Apple magazine from 1980-1992) had a coding contest every month. The rules: Maximum 2 lines of Apple BASIC. IT was probably my favorite part of the magazine. There were some amazing submissions.

        • Re:Nostalgia ... (Score:4, Informative)

          by arth1 ( 260657 ) on Monday February 20, 2012 @10:13AM (#39099483) Homepage Journal

          You can still download those.
          There are also annual "one-liner" contests for various languages, which have been around for at least a generation.
          perl is probably the winner in one-liners. Including useful utilities like (all way smaller than 144 bytes):
          perl -00pe0 filename
          ... which will strip all superfluous blank lines from a file, leaving just single blank lines.
          Or, to find all primes between 5000 and 5100:
          seq 5000 5100 | perl -lne 'print if (1x$_) !~ /^1?$|^(11+?)\1+$/''
          Or, a simple working web server - actually useful to pull files from one machine to another:
          perl -MIO::All -e 'io(":8080")->fork->accept->(sub {$_[0] < io(-x $1 ? "./$1 |" : $1) if /^GET \/(.*) /})'

          There's also this DOS/Windows gem:
          X5O!P%@AP[4\PZX54(P^)7CC)7}$EICAR-STANDARD-ANTIVIRUS-TEST-FILE!$H+H*

          Save it as eicar.com and your antivirus software should pick it up.
          And you can execute it too (it's harmless, of course). A 69 byte binary executable that only contains ASCII characters.

          All in all, the article submission isn't all that impressive.

    • by peragrin ( 659227 ) on Sunday February 19, 2012 @11:07AM (#39092809)

      However the code itself is 140 bytes, the number of libraries required to operate it is at 10 gigabytes.

      • by TheLink ( 130905 )
        So what? If enough computers meet the requirements then it's fine in my book. After all my computer requires electricity to work.

        In fact if it's cross platform on multiple browsers it's better in some ways than those intros/demos that only ran on one specific platform (I won't be surprised if some of those were even fussier and wouldn't work on some variants of the same platform).
      • by mrmeval ( 662166 )

        I remember writing code for a 1541 floppy that had to fit in a sector if I recall correctly. I never figured out how to daisy chain that as some did and I never went farther with programming.

        I'd have no issue with dense code in that context if the libraries would be available with any standard browser install. I would take exception with how javascript pulls in code over the network. Most languages are not very good if you can't use an external library at compile or run time but requiring any library to be

    • Reminds me of those very same days and renews my joy that we now have the freedom to use "inefficient," mnemonically useful names for variables and functions along with coding conventions that give the next programmer at least a remote chance to understand and support the code without great genius.
    • by _merlin ( 160982 )

      That's not even true. The original Mac had 64kB ROM, and 28kB of it was taken up by the QuickDraw graphics library. The 512Ke and Plus had a massive 128kB ROM. The ROM size went up to 256kB with the SE and II, then doubled again to 512kB with the IIci. It eventually got up to 1MB with the Quadra. The biggest classic Mac ROMs were 2MB in the Quadra AV and "blackbird" PowerBook 500 series.

    • by Tarsir ( 1175373 )
      128K? What a bunch of bloated crapware. I was working on code that had to fit within 28K last year
      • by tibit ( 1762298 )

        Seconded. I still deal with eZ8, a Harvard architecture platform that has 2kb of RAM and 16kb of code EEPROM on the particular chip I'm using. And then there's XMOS XS1 with 64kb of RAM that has to fit all the code and data for up to 8 threads of execution, running at an aggregate 500MIPS. Yet you can code some pretty amazing stuff on both.

    • by cshark ( 673578 )
      [script type="snobbery"] Looking at whole thing though, it feels kind of inefficient to render the whole board every time you move a piece around, and it's certainly not salable. I mean, what if there were more controls, or a bigger board? This thing would fall apart completely. [/script]
  • by Dark$ide ( 732508 ) on Sunday February 19, 2012 @10:33AM (#39092585) Journal
    Take a look at the source code [github.com]

    You'll love the non-restrictive EULA.

  • Somewhat Misleading (Score:5, Informative)

    by iONiUM ( 530420 ) on Sunday February 19, 2012 @10:36AM (#39092613) Journal

    Not to diminish their accomplishment, because this is very cool, but the 140 byte implementation is the base logic, it's not the actual printing or keyboard handling. Maybe that's nitpicking, but technically you can't just copy/paste that code and have the game, so I find the summary misleading.

  • Dear /. Overlords (Score:5, Informative)

    by TubeSteak ( 669689 ) on Sunday February 19, 2012 @10:38AM (#39092631) Journal

    so if your bored

    Dear /. Overlords,

    Would it be too much trouble to plug some type of grammar and spelling module into the slash-code?
    Not for us, the /. users; for you, the /. editors. I believe that in this wonderful age of computing, we wouldn't
    begrudge you guys a little help before you hit "submit."

    Sincerely,
    You're

  • Not 140 bytes (Score:4, Insightful)

    by sakdoctor ( 1087155 ) on Sunday February 19, 2012 @10:38AM (#39092637) Homepage

    The function requires an animation loop and event handler otherwise it does nothing. After that, it's way more than 140 bytes.

    • Ok. But considering the trend in using whatever memory and resources are available, the currently available Tetrises would rather take 140 MB. Many programmers just build ridiculously inefficient and inelegant algorithms, just because the amount of resources let them do so.
      • by mysidia ( 191772 )

        By the time you add all the bytes used by the Web Browser and OS required to run this software, it's probably larger than 140MB.

        A 140 byte bootable Tetris floppy image would be much more interesting

    • Re:Not 140 bytes (Score:5, Insightful)

      by Gavin Scott ( 15916 ) on Sunday February 19, 2012 @11:18AM (#39092847)

      Yes, it's about 816 characters in total. This is complete fail compared to the kind of stuff that's done for the IOCCC competition. The 140 byte function they wrote implements once tiny part of the whole thing, and looking at it suggests that there really aren't going to be many interesting programs possible in 140 bytes of javascript.

      If you want to see actually impressive tiny programs written in 2K of C code, like the guy who wrote an entire BASIC interpreter one year and then followed it up with a compiler for the same language the next year, then check out the IOCCC sinners page:

      http://www.ioccc.org/years.html [ioccc.org]

      G.

  • by lobiusmoop ( 305328 ) on Sunday February 19, 2012 @10:49AM (#39092693) Homepage
  • More! (Score:4, Insightful)

    by slasho81 ( 455509 ) on Sunday February 19, 2012 @11:04AM (#39092781)
    Now, this is proper Slashdot material. More of this, please!
  • When I was young, we had to code an entire web browser in 8 12 bit words using only the three switches on the front panel.

    And we were grateful to have it.

  • If you look at the site [github.com], it is obvious that this is neither Tetris nor an implementation of Tetris. It is just a part of the game that when given the current layout in certain encoding, the current user input and some other state variables can tell you what is the next state. All of this is meaningless unless you know what should you do with this state information. Crucially, included is neither the drivers to read user input or the method to render the game board for display.

    So yes, this is one part of an

  • ... because they're pretending that the many tens of thousands of lines of code in the JavaScript interpreter don't count. They do, because those 140 bytes are useless without it.

    • ... because they're pretending that the many tens of thousands of lines of code in the OS and libraries don't count ...
      ... because they're pretending that the many tens of thousands of lines of HDL code in the processor don't count ...

      True demoscener builds his own CPU out of transistors and resistors. Some suggest that using logic gates ICs is acceptable, but they're wimps.

      • Re: (Score:2, Offtopic)

        by macraig ( 621737 )

        I just knew that some contrary doofus looking for a pissing contest would trot out a comment like yours. Why don't I see the exact same foolishness from you repeated in reply to the other comments that made exactly the same point I did? Congratulations, you win the argument on a laughable Relativist technicality that no one but you takes seriously.

  • by Hentes ( 2461350 ) on Sunday February 19, 2012 @11:31AM (#39092907)

    Twitter uses utf-8, so the size of a tweet is 1120 bytes.

  • figuring out how it works and there is lots of help on the site — so if your bored how about the 140 character challenge?

    If my WHAT is bored? I don't get this line.

  • Some time ago, I participated in a contest to see who could write the shortest Pong game in x86 assembler. Of course entries used BIOS calls and ran on the text screen. The winner's entry was 50 bytes. Got about 30 entries in all, averaging somewhere around 75 bytes.
  • Fucken (Score:2, Informative)

    by Anonymous Coward

    proofread you're submissions. Sheesh, youse merkins all y'all illiterate, er wat?

  • by jez9999 ( 618189 ) on Sunday February 19, 2012 @12:05PM (#39093185) Homepage Journal

    Here is my Tetris implementation:

    a()

    However, it only works on custom Javascript interpreters which have a global a() function that implements a full game of Tetris.

    • by xhrit ( 915936 )
      That is the first thing I thought when I looked at the code. The answer to the question "Is it possible to write a JavaScript program in no more than a tweet's length?" is yes, but that tetris-like demo is not proof. It is not even a real game since there are no victory conditions or score. It has no usefulness besides a demo, and since they hid code in external functions it's usefulness as a demonstration is insubstantial.

      Hello World is enough proof. Hello World is no more then a tweets length, and is act
  • Geesh... (Score:4, Informative)

    by taoboy ( 118003 ) on Sunday February 19, 2012 @12:23PM (#39093319)

    #!/usr/bin/perl

    use StupidShitIveWritten::Tetris(tetris);

    tetris;

  • Let's have a competition where we pull out some old hardware (like the 2600) and THEN see what they can do.

    We all know the old guys did it. What about today's younger coders? Can they program something fun and useful in 4K using the programming languages available a 2600?

    • by swb ( 14022 )

      Do you mean to limit them by programming languages or the internal resources on a 2600 system?

      Theoretically, newer languages and better tool chains might possibly result in something as good or better than what 2600 developers produced at the time. There may have been coding techniques that were known or attempted but just proved prohibitive with the tool chains of the the 2600 era.

      On the other hand, 2600 developers weren't distracted with the web and were razor-focused hand -coded and -debugged assembler.

    • Can they program something fun and useful in 4K using the programming languages available a 2600?

      Bear in mind that the 4KB was maximum size of a standard (non bank-switched) *ROM* cartridge.

      Of course, one would need some RAM for keeping track of variables, data, etc. as well, and the 2600 had some onboard- a grand total of 128 *bytes*!

      Plus, there was no screen memory as such, just the graphics chip registers which held enough data to generate one line, and had to be updated every time you wanted a subsequent line to be different.

  • How long until The Tetris Company fires its next round of takedowns?
    • How long until The Tetris Company fires its next round of takedowns?

      They'll start once the lawyers stop salivating on the license included with the javascript.

      They're seeing dollar sings already.

  • I wouldn't be surprised if, one day, W3C would add tetris to the (already hairy) HTML specification. Then, a mere 9 bytes would suffice:

    <tetris/>

    You see, sadly, the most effective language for targeting the web, HTML, was never designed for experienced programmers but for the average joe who doesn't care about formal languages anyway.

    • by mysidia ( 191772 )

      but for the average joe who doesn't care about formal languages anyway.

      Yeah... the average joe can't use HTML. They would use a visual editor.

  • by mysidia ( 191772 ) on Sunday February 19, 2012 @01:35PM (#39093893)

    This is easier than any game of Tetris I ever played... there's a nice grid of dots displayed to line up pieces with.

    And when you get a two-column piece, it allows you to move the right half of the piece off screen, causing the piece to "wrap" around the edge of the screen....

  • by Hugh Pickens writes ( 1984118 ) on Sunday February 19, 2012 @01:51PM (#39093995) Homepage
    The world's smallest game of Tetris took place in 2002 under an electron microscope [youtube.com] using 42 glass microspheres at the Department of Physics of Complex Systems in Amsterdam.

    A real-life implementation of the evergreen arcade game Tetris was obtained by optically trapping 42 glass microspheres (1 micrometer diameter) in a 25 micrometer x 20 micrometer sized field under a microscope. Their positions were then steered with a computer. The generation of multiple traps, as well as the computer-steering, was accomplished by the use of acousto-optic deflectors [joostenyvonne.nl]: devices that tuned the deflection of a laser beam for a very fast response.

  • .. in 128b, check this out for size: sponge [pouet.net]

    There are plenty more demos at that site.

  • Get off my lawn! (Score:4, Informative)

    by billcopc ( 196330 ) <vrillco@yahoo.com> on Sunday February 19, 2012 @05:35PM (#39095329) Homepage

    Back in the good ol' days, when men were men, and Java was just a retarded twinkle in Gosling's eye, we had 256-byte competitions in assembly language. Anything using an interpreter is an immediate disqualification, unless your interpreter + script somehow fit inside the 256 byte limit. Basically, any dependency that isn't part of the hardware, BIOS, or low-level OS functionality like disk I/O, must be included in the byte total. Libraries, interpreters, resource blobs, it all adds up.

    And now, a real Tetris in 256 bytes: http://www.users.globalnet.co.uk/~jchap/tvprotet.htm [globalnet.co.uk]

    Get that goddamned Javascript hack out of my face.

  • I and another wrote an alphametics solver in Perl in under 100 bytes. (e.g. SEND+MORE=MONEY. Each letter stands for a distinct digit. Find an assignment of digits to letters that makes the arithmetic correct.) Alas, I don't have the code to hand to post it. The basic algorithm was:
    (1) $x= pop @ARGV. If it is empty, quit.
    (2) If $x contains no letters, print it if it 'eval's to true.
    (3) otherwise pick a letter, and make copies of $x with that letter replaced by every digit not already in $x (unless doing so w

Life is a whim of several billion cells to be you for a while.

Working...