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?"
Binary Tetris (Score:2, Funny)
Binary Tetris?
http://a.fsdn.com/sd/topics/programming_64.png
Re:Binary Tetris (Score:4, Informative)
Binary Tetris is based on dominoes instead of tetrominoes and is called Dis.
Nostalgia ... (Score:5, Insightful)
Re:Nostalgia ... (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.
Comment removed (Score:5, Interesting)
Re:Nostalgia ... (Score:4, 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.
Re:Nostalgia ... (Score:4, Informative)
You can still download those.
... which will strip all superfluous blank lines from a file, leaving just single blank lines. /^1?$|^(11+?)\1+$/'' /^GET \/(.*) /})'
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
Or, to find all primes between 5000 and 5100:
seq 5000 5100 | perl -lne 'print if (1x$_) !~
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
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.
Re:Nostalgia ... (Score:5, Informative)
The european versions had just 1k (two 2114 chips of 1k x 4 bit)
Re:Nostalgia ... (Score:5, Informative)
Trust me, 1kB.
To clarify this, you're right that the original versions of the ZX80 [wikipedia.org] and ZX81 [wikipedia.org] both had 1KB onboard.
However, the US version of the ZX81 (the Timex Sinclair 1000 [wikipedia.org]) shipped with 2KB onboard, which is probably what the GP was thinking of.
Re:Nostalgia ... (Score:5, Funny)
However the code itself is 140 bytes, the number of libraries required to operate it is at 10 gigabytes.
Re: (Score:2)
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).
Re:Nostalgia ... (Score:5, Informative)
Re:Nostalgia ... (Score:4, Funny)
Re: (Score:2)
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
Re:Nostalgia ... (Score:5, Insightful)
t();
(That's a function call to an external library that does all the other shit needed)
Re: (Score:2)
Has that been added as a Golf builtin yet?
Re:Nostalgia ... (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()
Re:Nostalgia ... (Score:5, Funny)
Re:Nostalgia ... (Score:4, Informative)
that would be roughly 2.3 lines of a card catalog card (assumes 12 point type and a 3X5 card)
Re: (Score:3)
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.
Fail - it's actually 845 bytes. (Score:5, Informative)
Re: (Score:3)
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
Re: (Score:2)
Re: (Score:3)
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.
Re: (Score:2)
Re: (Score:3)
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.
Re: (Score:2)
Read the source code - love the licence.txt (Score:5, Interesting)
You'll love the non-restrictive EULA.
Re: (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.
In Soviet Rus. LICENSE wastes you! (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.
Re:Read the source code - love the licence.txt (Score:5, Informative)
You'll love the non-restrictive EULA.
It's called WTFPL [wikipedia.org].
Re: (Score:3)
But it's version 2? I wonder how bad version 1 was!
Re:Read the source code - love the licence.txt (Score:4, Funny)
Well, version 2 is 'binary Tetris', so I just assume that version 1 was 'unary Tetris'.
Re: (Score:2)
Nitpick: It's not an EULA, just a copyright license.
EULA means End-User license agreement, while this license doesn't apply to end users, just to people re-distributing the software.
Spoier Re:Read the source code - lov (Score:2)
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
Version 2, December 2004
Copyright (C) 2011 YOUR_NAME_HERE
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.
Re: (Score:2)
Now why did that get past the lameness filter? Is there some AI running in the background or is there uncooked meatware reading every post?
Oh my gods is that why the posts are so crazy? There's a million Indians approving all posts? Or is it a time clone of Cmdr Taco???
How hideous.
Re: (Score:2)
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
Seriously a great idea. I'm sure the GPL crowd will step in momentarily to tell everyone why it's a bad one, though.
Re:Read the source code - love the licence.txt (Score:4, Funny)
Re: (Score:2)
Re: (Score:2)
It doesn't have to be approved to be considered open source by the OSI, just comply with the definition.
It's on the FSF licenses list [gnu.org], though.
Re:Read the source code - love the licence.txt (Score:4, 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.
Re: (Score:3)
Somewhat Misleading (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.
Re: (Score:3)
Re:Somewhat Misleading (Score:5, Informative)
Almost kilobyte? Yep, not very impressive considering what people build in 1 kB of Javascript [js1k.com].
Not to mention all the cool things people stuff in 512 byte intros for demo parties.
Re:Somewhat Misleading (Score:5, Informative)
Re:Javascript in 1K (Score:4, Interesting)
The Chess entry makes a good sobriety test! : )
http://js1k.com/2010-first/demo/750 [js1k.com]
Re: (Score:2)
Nice... However it does not implement castling [wikipedia.org].
Re: (Score:2)
In case anyone else tries this in Firefox, try it in Chrome and it will work.
As a devoted fan, I don't know what that says about my beloved Firefox. Is it possible that this was just written for Chrome's javascript implementation and doesn't necessarily mean one is better than the other?
Dear /. Overlords (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? /. users; for you, the /. editors. I believe that in this wonderful age of computing, we wouldn't
Not for us, the
begrudge you guys a little help before you hit "submit."
Sincerely,
You're
Re:Dear /. Overlords (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
Re: (Score:2)
Your being to picky. People care less about grammar these days ten most other things. Irregardless, there doing the best they can
Its not "ten" dumbasd. Its "then"!
Re:Dear /. Overlords (Score:5, 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?
Re: (Score:2)
By being hired by a manager who also has a degree in journalism.
Not 140 bytes (Score:4, Insightful)
The function requires an animation loop and event handler otherwise it does nothing. After that, it's way more than 140 bytes.
Optimization (Score:2)
Re: (Score:2)
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)
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.
Re:Not 140 bytes (Score:5, Funny)
Was supposed to be "winners" of course, but then "sinners" might well be the more appropriate term anyway...
G.
Still not as good as: (Score:5, Interesting)
Chess in 672 bytes [ox.ac.uk]
Re:Still not as good as: (Score:4, Informative)
Nor this http://survex.com/~olly/rheolism/ [survex.com]: 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
Re: (Score:2)
is it possible to write javascript in 140 chars? (Score:2)
null;
Hmm I could write Tetris... (Score:2)
More! (Score:4, Insightful)
Oh, we used to DREAM of having 140 bytes (Score:2, Funny)
And we were grateful to have it.
Not really Tetris, Not really an implementation (Score:2)
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
I call bullshit... (Score:2)
... 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.
Re: (Score:2)
... 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)
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.
Re: (Score:2)
*Compiled* code has always been where that line was drawn, so an interpreter counts as part of the code. The operating system and BIOS are on the other side of that line because they truly are "generic", and since programs can be written to be platform independent.
A tweet is longer than that (Score:3)
Twitter uses utf-8, so the size of a tweet is 1120 bytes.
Your bored (Score:2)
If my WHAT is bored? I don't get this line.
pong in 50 bytes of x86 assembler (Score:2)
Fucken (Score:2, Informative)
proofread you're submissions. Sheesh, youse merkins all y'all illiterate, er wat?
I have a shorter Tetris implementation (Score:5, Funny)
Here is my Tetris implementation:
However, it only works on custom Javascript interpreters which have a global a() function that implements a full game of Tetris.
Re: (Score:2)
Hello World is enough proof. Hello World is no more then a tweets length, and is act
Geesh... (Score:4, Informative)
#!/usr/bin/perl
use StupidShitIveWritten::Tetris(tetris);
tetris;
see the same programmers do it on an atari 2600 (Score:2)
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?
Re: (Score:2)
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.
Re: (Score:2)
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.
The Tetris Company (Score:2)
Re: (Score:2)
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.
html tag (Score:2)
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.
Re: (Score:2)
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.
Interesting (Score:3)
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....
The Smallest Game of Tetris (Score:3)
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.
You can do brilliant stuff (Score:2)
.. in 128b, check this out for size: sponge [pouet.net]
There are plenty more demos at that site.
Re: (Score:2)
Re: (Score:2)
Yeah, and I've been part of almost every production from outbreak [pouet.net] but I didn't come here to brag ;-)
(I'm thec of outbreak btw)
Re: (Score:2)
Re: (Score:2)
*presses invisible like button*
Get off my lawn! (Score:4, 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 [globalnet.co.uk]
Get that goddamned Javascript hack out of my face.
Alphametics in 100 bytes (Score:2)
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
Re:It is still requiring a virtual machine. (Score:5, Funny)
Re: (Score:3)
Re: (Score:2)
Not if you're using a Commodore Pet....
http://en.wikipedia.org/wiki/KERNAL [wikipedia.org]
Re:Obilg Bill Gates (if he ever said it) reference (Score:5, 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!"
Re: (Score:2)
Re: (Score:2)
that isn't old - how much space a webpage uses is a big deal based on your traffic levels..