Slashdot Mirror


Tetris In 140 Bytes

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?"

57 of 215 comments (clear)

  1. Binary Tetris by Anonymous Coward · · Score: 2, Funny

    Binary Tetris?

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

    1. Re:Binary Tetris by cupantae · · Score: 3, Informative

      Binary Tetris is based on dominoes instead of tetrominoes and is called Dis.

      --
      --
  2. Nostalgia ... by WrongSizeGlass · · Score: 5, Insightful

    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.

    1. Re:Nostalgia ... by arth1 · · Score: 5, Interesting

      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.

    2. Re:Nostalgia ... by peragrin · · Score: 5, Funny

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

      --
      i thought once I was found, but it was only a dream.
    3. Re:Nostalgia ... by __aamdvq1432 · · Score: 2

      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.

    4. Re:Nostalgia ... by _merlin · · Score: 2

      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.

    5. Re:Nostalgia ... by thesh0ck · · Score: 5, Informative

      The fact is.. only the math is 140bytes. If you view the source and scroll down you see there is way more than that to actually make it work. Including javascript for controlling the game and displaying the blocks. It is in fact 1361 bytes.

    6. Re:Nostalgia ... by Anonymous Coward · · Score: 5, Insightful

      Oh, well, in that case, allow me to introduce you to my 4 character Tetris program.

      t();

      (That's a function call to an external library that does all the other shit needed)

    7. Re:Nostalgia ... by MisterMidi · · Score: 4, Funny

      +1 insightful. We could make an entire OS in 140 bytes this way.

    8. Re:Nostalgia ... by hal2814 · · Score: 5, Funny

      A tweet? I'm not familiar with that metric. Maybe you could convert it to something more standard like Libraries of Congress.

    9. Re:Nostalgia ... by Anonymous Coward · · Score: 5, Informative

      The european versions had just 1k (two 2114 chips of 1k x 4 bit)

    10. Re:Nostalgia ... by tibit · · Score: 2

      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.

      --
      A successful API design takes a mixture of software design and pedagogy.
    11. Re:Nostalgia ... by Anonymous Coward · · Score: 5, Funny

      in javascript you don't need to end the last statement on a line with a semicolon, so you could reduce it to t()

    12. Re:Nostalgia ... by Dogtanian · · Score: 5, Informative

      Trust me, 1kB.

      To clarify this, you're right that the original versions of the ZX80 and ZX81 both had 1KB onboard.

      However, the US version of the ZX81 (the Timex Sinclair 1000) shipped with 2KB onboard, which is probably what the GP was thinking of.

      --
      "Slashdot - News and Chat Sites Deviant". (Click "homepage" link above for details).
    13. Re:Nostalgia ... by RobertLTux · · Score: 3, Informative

      that would be roughly 2.3 lines of a card catalog card (assumes 12 point type and a 3X5 card)

      --
      Any person using FTFY or editing my postings agrees to a US$50.00 charge
    14. Re:Nostalgia ... by hairyfeet · · Score: 4, Interesting

      Wow I thought we VIC-20 owners had it bad with our lousy 5Kb, man just the thought there was somebody out there that could out cheap old Jack Tramiel is kind of mind blowing in and of itself.

      As for TFA just imagine hoe much insane power we would have if they still made OSes and apps like every byte counted. Not to condone piracy or anything but if one were to try out the Tiny series like Tiny XP or Tiny 7 you'd find that with careful stripping one can make a modern Windows that damned near runs on the original WinXP specs and is snappy as hell. MSFT really needs to hire that guy as his Tiny series frankly stomps both the Win Embedded and WinFLP version quite badly. i guess that little hacker knows how to slim down their OS better than they do.

      --
      ACs don't waste your time replying, your posts are never seen by me.
    15. Re:Nostalgia ... by Zadaz · · Score: 3, Interesting

      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.

    16. Re:Nostalgia ... by arth1 · · Score: 3, Informative

      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.

    17. Re:Nostalgia ... by Anubis+IV · · Score: 2

      From what I can tell, the standard measure for Libraries of Congress (LoC) is 10TB of data, which was apparently estimated based only on the textual content of the physical materials stored, and without any consideration for the petabytes of digital storage that the Library claims to have.

      Based on that, you could express the length of a Tweet as roughly 1.27e-11 LoC in size.

  3. Read the source code - love the licence.txt by Dark$ide · · Score: 5, Interesting
    Take a look at the source code

    You'll love the non-restrictive EULA.

    --

    Sigs. We don't need no steenking sigs.

    1. Re:Read the source code - love the licence.txt by Anonymous Coward · · Score: 3, Funny

      Everyone is permitted to copy and distribute verbatim or modified
        copies of this license document, and changing it is allowed as long
        as the name is changed.

      Why should i have to change the name? I feel that is overly and unnecessarly restrictive.
      I should have the right not to change the name if i don't want to.
      This source code is useless to me.

    2. Re:Read the source code - love the licence.txt by Anonymous Coward · · Score: 5, Informative

      You'll love the non-restrictive EULA.

      It's called WTFPL.

    3. Re:Read the source code - love the licence.txt by Provocateur · · Score: 2

      But it's version 2? I wonder how bad version 1 was!

      --
      WARNING: Smartphones have side effects--most of them undocumented.
    4. Re:Read the source code - love the licence.txt by icebraining · · Score: 3, Informative

      I'm not sure if it's necessary or not, but in this particular case, it's a Tetris game, not a remote controller for sharks with freakin' lasers.

    5. Re:Read the source code - love the licence.txt by roman_mir · · Score: 3, Funny

      Well, version 2 is 'binary Tetris', so I just assume that version 1 was 'unary Tetris'.

    6. Re:Read the source code - love the licence.txt by Datamonstar · · Score: 3, Funny

      Not gonna read that. I'll just do what the fuck I want to!

      --
      The eternal struggle of good vs. evil begins within one's self.
    7. Re:Read the source code - love the licence.txt by PlatyPaul · · Score: 2

      I take it you missed the bonus level, then. Shame.

      --
      Misery loves company. Online misery loves unsuspecting random strangers.
  4. Somewhat Misleading by iONiUM · · Score: 5, Informative

    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.

    1. Re:Somewhat Misleading by melikamp · · Score: 2

      Indeed. The actual source has about 955 characters, which is not that impressive for a game so gimped.

    2. Re:Somewhat Misleading by anonymov · · Score: 4, Informative

      Almost kilobyte? Yep, not very impressive considering what people build in 1 kB of Javascript.

      Not to mention all the cool things people stuff in 512 byte intros for demo parties.

    3. Re:Somewhat Misleading by hydrofix · · Score: 5, Informative

      Here's actually a full Tetris with sound in 1016 characters!

  5. Dear /. Overlords by TubeSteak · · Score: 5, Informative

    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

    --
    [Fuck Beta]
    o0t!
    1. Re:Dear /. Overlords by Nerdfest · · Score: 5, Funny

      Your being to picky. People care less about grammar these days ten most other things. Irregardless, there doing the best they can

    2. Re:Dear /. Overlords by kelemvor4 · · Score: 4, Insightful

      Your being to picky. People care less about grammar these days ten most other things. Irregardless, there doing the best they can

      Was that as painful for you to write as it was for me to read?

    3. Re:Dear /. Overlords by Tyrannosaur · · Score: 2

      I had to read it about 3 times...

  6. Not 140 bytes by sakdoctor · · Score: 3, Insightful

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

    1. Re:Not 140 bytes by Gavin+Scott · · Score: 4, Insightful

      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

      G.

    2. Re:Not 140 bytes by Gavin+Scott · · Score: 4, Funny

      Was supposed to be "winners" of course, but then "sinners" might well be the more appropriate term anyway...

      G.

  7. Re:It is still requiring a virtual machine. by History's+Coming+To · · Score: 4, Funny

    To write that post you had to have a bunch of silicon doped to recreate basic logic gates, a kernal to pass it instructions, an OS to let you interact with the kernal, a browser to connect it to a worldwide network and so on. This is cheating. Real Slashdotters use a butterfly.

    --
    Please consider this account deleted, I just can't be bothered with the spam anymore.
  8. Still not as good as: by lobiusmoop · · Score: 5, Interesting
    --
    "I bless every day that I continue to live, for every day is pure profit."
    1. Re:Still not as good as: by pdh11 · · Score: 3, Informative

      Nor this http://survex.com/~olly/rheolism/: real Tetris in one line of BBC BASIC, 255 bytes after tokenisation. All the shapes are stored in one 32-bit constant. It's just amazing.

      Peter

  9. More! by slasho81 · · Score: 3, Insightful

    Now, this is proper Slashdot material. More of this, please!

  10. In Soviet Rus. LICENSE wastes you! by JCPM · · Score: 2

    But if they include the LICENSE, it's much bigger than 140 bytes, some as >200 times the size of the program. The LICENSE is the only wasteful thing that did exist on the Earth.

    JCPM: to erase the LICENSE and then this program is much smaller, adjusted to 140 bytes, otherwise, it will be lying me.

  11. A tweet is longer than that by Hentes · · Score: 2

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

  12. Re:It is still requiring a virtual machine. by History's+Coming+To · · Score: 2

    Hey, if there's open source comedy out there why bother bootstrapping your own gags?

    --
    Please consider this account deleted, I just can't be bothered with the spam anymore.
  13. Your bored by Higgins_Boson · · Score: 2

    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.

  14. Fucken by Anonymous Coward · · Score: 2, Informative

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

  15. I have a shorter Tetris implementation by jez9999 · · Score: 4, Funny

    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.

  16. Geesh... by taoboy · · Score: 4, Informative

    #!/usr/bin/perl

    use StupidShitIveWritten::Tetris(tetris);

    tetris;

  17. Interesting by mysidia · · Score: 2

    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....

  18. Fail - it's actually 845 bytes. by Barbara,+not+Barbie · · Score: 5, Informative

    If you actually look at the code, just the javascript is 733 bytes after taking out all whitespece, etc, not 140. And this doesn't count the html that embeds it - an additional 112 bytes, for a total of 845 bytes.

    --
    Let's call it what it is, Anti-Social Media.
    1. Re:Fail - it's actually 845 bytes. by Amouth · · Score: 2

      yea all i saw was a single function under 140.. but it doesn't have any controls or display.. not what i consider a full game

      --
      '...if only "Jumping to a Conclusion" was an event in the Olympics.'
  19. Re:Obilg Bill Gates (if he ever said it) reference by MobileTatsu-NJG · · Score: 4, Funny

    Did you know that the word 'obligatory' came from the Greek God Obligatius who, on occasion, would entertain Zeus with stand-up philosophy? One night he told an off-color joke about Rhea, it made all the gods laugh except for one. Zeus was so angry he punished Obligatius by making him tell the same joke over and over again until he can find somebody who'll laugh at it. To this day, he still wanders the earth saying "640k should be enough for everybody!"

    --

    "I like to lick butts!" by MobileTatsu-NJG (#32700246) (Score:5, Informative)

  20. The Smallest Game of Tetris by Hugh+Pickens+writes · · Score: 2
    The world's smallest game of Tetris took place in 2002 under an electron microscope 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: devices that tuned the deflection of a laser beam for a very fast response.

  21. Re:Javascript in 1K by TaoPhoenix · · Score: 3, Interesting

    The Chess entry makes a good sobriety test! : )

    http://js1k.com/2010-first/demo/750

    --
    My first Journal Entry ever, in 8 years! http://slashdot.org/journal/365947/aphelion-scifi-fantasy-horror-poetry-webzine
  22. Get off my lawn! by billcopc · · Score: 3, Informative

    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

    Get that goddamned Javascript hack out of my face.

    --
    -Billco, Fnarg.com