A game whose source code fits in one tweet
github.com
github.com
python3 -c "import random;p=lambda:random.choice('7♪♫♣♠♦♥◄☼☽');[print('|'.join([p(),p(),p()]),end='\r') for i in range(8**5)]"Here's mine.
$ python -c 'import random;L=sorted(str(random.randint(1,9)) for i in range(4));a=raw_input(L);print(eval(a)==24,sorted(filter(str.isdigit,a))==L)'
['2', '6', '7', '8']8*(7+2-6)
(True, True)
Try to make it print (True, True) without abusing eval too much (intended to be +-*/() only with digits as tokens).A nicer interface, but too long:
import random;L=sorted(str(random.randint(1,9)) for i in range(4));a=raw_input(" ".join(L)+"\n> ");print(eval(a)==24,sorted(filter(str.isdigit,a))==L) while(true){f()}The start tag is mandatory. The end tag may be omitted if the <p> element is immediately followed by an <address>, <article>, <aside>, <blockquote>, <div>, <dl>, <fieldset>, <footer>, <form>, <h1>, <h2>, <h3>, <h4>, <h5>, <h6>, <header>, <hr>, <menu>, <nav>, <ol>, <pre>, <section>, <table>, <ul> or another <p> element, or if there is no more content in the parent element and the parent element is not an <a> element.
Actually, what you call "very specific cases" are in fact, well, all reasonable cases. That list consists of all block level elements that can appear in `body`, so the statement could be reworded, that "<p> cannot contain any block-level element, so any inline element after <p> falls in, any block level element ends opened <p>".
Funny fact is that presence of optional end tags means nearly nothing for HTML parsers used in current browsers, they just ignore them. Some border cases regarding white space exists, or at least existed in the past, but in general, if you feed browser with document
<!doctype html><html><head><title>a</title></head><body><table><tbody><tr><td><p>b</p></td></tr></tbody></table></body></html>`
or <!doctype html><title>a</title><table><tr><td><p>b</table>`
makes absolutely no difference. Both will result in exactly same DOM tree, both are "100% valid W3C HTML documents".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);- show it on 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/
- 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
Here's a 2048/Threes-clone in <700 characters (or 5 tweets): https://twitter.com/eigenbom/status/615424395192877056
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)
http://xem.github.io/articles/#implicitgetelementbyid_en
Cheers :)
Personally I find it handy for messing around in jsfiddle and the like:
<pre id="out"></pre>
[...]
out.innerHTML += some_result;curl http://www.hackerz-r-us.ru/really_awesome_game.sh | sudo bash #YouveBeenP0wnd
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) 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...
http://countercomplex.blogspot.co.at/2011/10/algorithmic-sym...
Most of these would also fit in a single tweet ..
(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!)
s += 1
a.style.margin = (s + e) % 300The code you posted is essentially equivalent to "s = s + 1; a.style.margin = s + e % 300".
http://lalwanivikas.github.io/window-game/
(Concept inspired from Jennifer Dewalt's project, but code is entirely mine :))
<!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)