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?"
Binary Tetris?
http://a.fsdn.com/sd/topics/programming_64.png
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.
You'll love the non-restrictive EULA.
Sigs. We don't need no steenking sigs.
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.
... is more than 140 bytes.
To have the program run, you have to have a javascript interpreter. That is cheating.
If one of the 2-blocks goes to far to the side, it will wrap around. If one of the 1-blocks goes to far to the side... I'm not really sure what happens. Something odd at any rate. You can use it to tunnel them to the bottom, though.
I'm not really sure what could be cut down to make space for the bounds-checking, though. Maybe the constraints are just too tight.
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
[Fuck Beta]
o0t!
The function requires an animation loop and event handler otherwise it does nothing. After that, it's way more than 140 bytes.
My bored what!?!
Ofcourse Bill Gates never said such a thing.
Chess in 672 bytes
"I bless every day that I continue to live, for every day is pure profit."
Only the model part of the model-view-controller program is 140 bytes.
null;
Now, this is proper Slashdot material. More of this, please!
And we were grateful to have it.
Tetris
If you look at the site, 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 implementation of a Tetris. But then again, any given block of code less than 140 characters in length from any full implementation has also a claim for being a part of an implementation of "Tetris". So I therefore proclaim that I have beaten them by my even shorter "implementation", which simply consists of the letter u (a part of crucial JavaScript keywords like "function" and "return") for it has an equally valid claim for an "implementation" of "Tetris" as this function, in some perverted regard ;).
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.
... Javascript was built to be human-readable.
If those commands were shorter, you could probably fit the rest of the code in a small space too.
You could probably write a wrapper layer to make all those commands 1 letter, well, most.
Can you ever make "return" smaller? I tried a few ways, but never managed to do it so gave up.
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.
Slashdot, fix the reply notifications... You won't get away with it...
...in only 6 bytes.
Slashdot, fix the reply notifications... You won't get away with it...
... 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.
Twitter uses utf-8, so the size of a tweet is 1120 bytes.
Try pressing left until you go off the screen. Wooo, secret level! =D
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.
Intellectual Property is a monopolistic, selfish, and defective concept. It is "tyranny over the mind of man"
Each one of the mobil phones will receive an unauthorized hidden 140-byte SMS Javascript message that will used for Distributed Denial of Service against mobil telephone operators as by example, the monopolied ATandT in USofA.
JCPM: useful as screensaver of SMS Low-Orbit Canyon DDoS, and the consumer will be playing gratis to this game Tetris.
proofread you're submissions. Sheesh, youse merkins all y'all illiterate, er wat?
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.
== Jez ==
Do you miss Firefox? Try Pale Moon.
#!/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?
I've had a double take after seeing 'grammar' and 'irregardless' in the same line and had to re-read it all. Well played sir :)
How long until The Tetris Company fires its next round of takedowns?
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.
If Pandora's box is destined to be opened, *I* want to be the one to open it.
Make them do it in Brainfuck.
Has all the coders of the 80's/90's demoscene died already?
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....
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.
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)
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.
Ponca City, We Love You
.. in 128b, check this out for size: sponge
There are plenty more demos at that site.
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.
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
0. You just DO WHAT THE FUCK YOU WANT TO.
I'd go on a Vegan diet but the delivery time from Vega is too long. --brownkitty
A couple of years ago, there was an album released of twitter programmed that made music with SuperCollider. Some of the music on it is pretty impressive, especially given the constraints.
http://supercollider.sourceforge.net/sc140/
that isn't old - how much space a webpage uses is a big deal based on your traffic levels..
'...if only "Jumping to a Conclusion" was an event in the Olympics.'
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
Making a tetris solver is non-trivial problem, mathematically related to the minimal subcover problem and the best
one can do is an approximation algorithm, (the standard approach would be via some kind of greedy matching algorithm
for mapping blocks into holes). There are even inapproximability results for hard limits on the accuracy of polynomial time
approximate solutions. It's probably NP-complete, (the minimal subcover problem from combinatorial topology certainly is),
so If you can write a polynomial time perfect tetris solver, prizes and place in the halls of history await...
Combinatorial topological entropy FTW!
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
Nice... However it does not implement castling.
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 would give a number with a leading 0). Push these back onto @ARGV.
(4) loop to (1).
To run, give the problem in Perl format on the command line:
$ perl alphameticssolver send+more==money
As it is doing an exhaustive search of up to 10! potential solutions, it takes a few minutes to run.
Quattuor res in hoc mundo sanctae sunt: libri, liberi, libertas et liberalitas.
But there are some bugs in it, like scroll your block left left left and it fills the screen with blocks, while also taking the block back up the screen..... so nice idea nice try but no cigar! it cant be called a game it can be called a test demo, not much more! Sorry for being so harsh.
http://luckyredfish.com
In the 1970s I won a programming contest for the shortest program to calculate the highest power of two that divides into a given number (e.g, given 12 the answer is 4 as 4 divides into 12 but 8 does not). My solution took 4 bytes and was the only one that did not have a loop in it. The person judging them told me that he originally threw it in the bin as it obviously couldn't work without a loop. Later he got curious and tried it out and found it always worked. He said that he could not believe that he could not understand how a 4 byte program worked. It was in IBM 360 assembler and consisted of LCR y,x then NR y,x.
Does /. have any editors?
It should be "so if you're bored," not "so if your bored."
You're welcome.
This isn't Tetris.... Tetra, meaning four, is the basis of that name... the blocks in Tetris are made up of four cells. However, in this game, they are either one cell or two cells. So at most I would call it Binary Block Game or something like that.
Amazing accomplishment, nonetheless.
The game is buggy as hell, make it better.
Anyone remember the last page of every issue of Nibble, that featured "two liner" contests? The goal was to write something in two lines of Applesoft basic, and the winners always managed to blow my mind. Beagle Bros released a disk of of these in the early 80's.
Glad to see this kind of challenge returning!
https://www.accountkiller.com/removal-requested
Reminds me of those wonderful 256 byte PC assembly demo compos.
"Nine times out of ten, starting a fire is not the best way to solve the problem." - my wife
The programming category icon of Slashdot could be a screenshot of this game.
Screw these arguments about byte counts. I think it's just cool to play ASCII versions of old-school vid-games.
Where's ASCII PacMan and Space Invaders?
Table-ized A.I.
Just trying this "awesome" Tetris. By continuos typing [right arrow] it brokes the display. Funny :)
But he did say "What's a network?"
++ Say to Elrond "Hello.".
Elrond says "No.". Elrond gives you some lunch.
Wow, that's actually kind of beautiful -- with the same beauty as a good mathematical proof or Man's most efficient invention: the spork.
GeekDad, TED speaker, Wipeout loser, author of Brain Trust
140 bytes + the javascript interpreter. Give me tetris in 140 bytes of machine code, or shutup.