
A game whose source code fits in one tweet - eigenbom
https://github.com/omnus/tiny-twitch
======
arocks
If you liked this then you might find my Python one liner games interesting
[1]. They fit a tweet in most cases.

[1]: [http://arunrocks.com/python-one-liner-
games/](http://arunrocks.com/python-one-liner-games/)

~~~
simi_
For some reason copy-pasting some of those into iTerm2 doesn't work.

[http://i.imgur.com/GEMAeM8.png](http://i.imgur.com/GEMAeM8.png)

~~~
vanous
not on a mac myself, but make sure to use python 3

    
    
       python3 -c "import random;p=lambda:random.choice('7♪♫♣♠♦♥◄☼☽');[print('|'.join([p(),p(),p()]),end='\r') for i in range(8**5)]"

------
escherize
I'm sorry I'm a dirty cheat: [http://fetchh--
captured.s3.amazonaws.com/Monosnap_2015-06-30...](http://fetchh--
captured.s3.amazonaws.com/Monosnap_2015-06-30_14-51-27.png)

    
    
        while(true){f()}

------
shubhamjain
OP can save a few more characters by not using 'var' and using 'E' notation
for representing 15000, i.e, 15E3, or better, 2E4.

~~~
ivanca
He can save 14 more if instead of creating a function he copies the function
content inside of 'onclick'. And he can save one by using +new Date instead of
Date.now().

~~~
sgibat
Better yet, set a variable to Date.now since it's called twice.

~~~
ajanuary
It's called at different times so will return different values, which is
important.

~~~
ahoge
They meant something like "var n = Date.now".

However, there is no guarantee that this will work since it assumes that
`this` isn't used by that function.

E.g. if you want to do something like that with console.log or
document.querySelector, you have to use bind:

    
    
      var log = console.log.bind(console);
      var qs = document.querySelector.bind(document);

------
Omnus
Author here - I'll implement some of these suggestions and see if the extra
space might allow for something a little more interesting. It's a pleasant
surprise to see a pull request on this little thing.

------
xem
Cool! some suggestions:

\- show it on
[http://www.reddit.com/r/tinycode/](http://www.reddit.com/r/tinycode/)

\- if you aim for low character count instead of low byte count, you can pass
your code through my unicide packer here:
[http://xem.github.io/obfuscatweet/](http://xem.github.io/obfuscatweet/)

\- Golf your code even more (using the tips of the other comments), and use
all the remaining chars to add features to your game and fill the 140 chars of
a tweet :)

Cheers

------
chrismorgan
I cut the size down by 39 bytes in [https://github.com/omnus/tiny-
twitch/pull/1](https://github.com/omnus/tiny-twitch/pull/1). You can trade 36
of those bytes for “legal HTML 5” status, too.

------
eigenbom
A few of us were doing this over on Twitter, with the typical "guess a number"
games. But Alex's was the best so far! I built a few games, but all of them
were too big.

Here's a 2048/Threes-clone in <700 characters (or 5 tweets):
[https://twitter.com/eigenbom/status/615424395192877056](https://twitter.com/eigenbom/status/615424395192877056)

------
pavel_lishin
Cute; I didn't realize that the element's ID implicitly mapped it to a
javascript variable in Chrome.

~~~
67726e
Can anyone speak a bit more to that? I was wondering if this was just a
convenience feature that browsers added or something that has been in
Javascript all along?

~~~
rev087
Has been like this for as long as I can remember (at least back to IE6).

~~~
Klonoar
Yup - in fact there's an old bug that jQuery (in versions < 2, I believe)
accounts for where IE would return elements with a name equal to the id you're
searching for as the underlying system there was all wonky.

e.g:

    
    
        <input name="test">
        <div id="test">
    
        document.getElementById('test'); // <input> in IE6
    

I believe this also wound up in some Webkit and Opera releases, perhaps for
emulation. Someone more knowledgeable about it all should feel free to correct
me if I'm wrong though.

(Edited for code formatting, I don't comment too much these days)

------
bigiain
Was half expecting this to be:

curl [http://www.hackerz-r-us.ru/really_awesome_game.sh](http://www.hackerz-r-
us.ru/really_awesome_game.sh) | sudo bash #YouveBeenP0wnd

------
david-given
One thing I've always meant to do was to put together a system for loading and
saving Sinclair ZX81 games via Twitter messages.

Depending on how much you cheat, you can get about two bytes of data per
Twitter character. That'd allow 256 bytes of game to live comfortably within a
single twit, which is a quarter of an unexpanded ZX81 RAM. By comparison, that
would take almost ten seconds to load off tape. You should be able to get a
respectable ZX81 game in that.

With something like the JtyOne Javascript ZX81 emulator
([http://www.zx81stuff.org.uk/zx81/jtyone.html](http://www.zx81stuff.org.uk/zx81/jtyone.html))
and some Twitter interaction, the whole process should be pretty seamless ---
click on a twit to play; modify it using the ZX81's built-in _cough_ IDE;
click on a button to reshare...

------
omgitstom
And that kept my interest for about 140 seconds. Pretty damn good
character:fun ratio. Bravo!

------
umeshunni
If you're interested in really small games, the smallest game is Chess written
in 487 bytes of x86 machine code:
[http://www.pouet.net/prod.php?which=64962](http://www.pouet.net/prod.php?which=64962)
Source code here:
[http://olivier.poudade.free.fr/src/BootChess.asm](http://olivier.poudade.free.fr/src/BootChess.asm)

------
fit2rule
I'm not really a gamer, but I do love me some synth one-liners:

[http://countercomplex.blogspot.co.at/2011/10/algorithmic-
sym...](http://countercomplex.blogspot.co.at/2011/10/algorithmic-symphonies-
from-one-line-of.html)

Most of these would also fit in a single tweet ..

~~~
JonnieCache
It's OT but I can't resist: I recently found out that a selection of these
little "synths" have been implemented in the chipsounds VST instrument using
its bandlimited oscillators. You can play them up and down the keyboard and
they sound _awesome._

[http://www.plogue.com/products/chipsounds/](http://www.plogue.com/products/chipsounds/)

~~~
fit2rule
Wow, that is really lovely .. thanks for pointing that out!

(I'm really more of a hardware guy myself, love to strip the SID's from any
C64's I find in the trash .. and of course synths (analog and digital) are
really a different subject altogether .. but I'll check out chipsounds on a
DAW next time I get a chance. Ta!)

~~~
JonnieCache
You will enjoy their blog:
[http://ploguechipsounds.blogspot.co.uk/](http://ploguechipsounds.blogspot.co.uk/)

~~~
fit2rule
You are correct! Thank you!

------
wunderlust
What exactly is happening here: "a.style.margin=++s+e%300"? (Specifically, the
"++" part.)

~~~
mgraczyk
Increment global state variable, add it to e, which is the number of
milliseconds the game has been running modulo 300. Then set the margin size to
that value. It's a simple pseudo-pseudorandom number generator.

------
lalwanivikas
Reminds me of a game I made while learning to code:

[http://lalwanivikas.github.io/window-
game/](http://lalwanivikas.github.io/window-game/)

(Concept inspired from Jennifer Dewalt's project, but code is entirely mine
:))

------
DaveSapien
Doesn't actually fit in a tweet. 12 characters too long...am I missing
something?

~~~
eigenbom
I think the . expands to a url so you have to use the zero-width space trick.

------
asgard1024
Reminds me when my father showed me "number guessing" game on TI-57
calculator. It had 50 instructions (button presses) of memory. It's
interesting that the size wasn't that a big deal then. :-)

------
dblotsky
Totally exploiting the fact invalid HTML is accepted by modern browsers. :P

~~~
chrismorgan
Somewhat, but it can still be fitted in legal HTML 5 in 137 bytes:

    
    
        <!DOCTYPE html><title>X</title><script>s=0,t=Date.now()</script><p onclick="(e=Date.now()-t)<15e3?style.margin=++s+e%300+'px':alert(s)">X
    

(Note that the original version is at least 36 bytes larger than it need be:
[https://github.com/omnus/tiny-twitch/pull/1](https://github.com/omnus/tiny-
twitch/pull/1))

------
bartbes
A few years ago I put a tiny game in a data uri in a QR code, unfortunately I
lost the QR code, but I thought it was a neat concept.

------
naugtur
Shorter version: <p
onclick=n=Date.now;id||(t=n(id=s=0));(e=n(++s)-t)<2E4?style.margin=e%300:alert(s)>X

------
the_duck
This game makes me feel like a cat.

------
jakejake
increments s before doing the rest of the calculation?

~~~
tylersmith
All that matters is that s changes for each call. It really doesn't matter
what the value is or how it changes. In this case incrementing afterwards
would be "s+++e%300" which looks gross and using any parenthesis for clarity
would take up more space.

