# Binary Tetris in tweets

There was recently (a few years back) some buzz on programming websites about an implementation of Tetris in 140 Bytes. ...

It turns out that although it is small, it is a simplified version of Tetris, and not even a complete implementation. Only the core logic function fits in 140 bytes of Javascript. To actually run it, you need another ~840 characters of HTML.

We can do better!
This challenge is to implement a complete version of "Binary Tetris" in as few tweets as possible.

Binary Tetris Rules:

• The program must display a playing field containing at least 5 columns and 6 rows of cells.
• Any method of display may be used, as long as the blocks and the edges of the field are clearly marked.
• There must be at least two types of blocks: # and ##. Additional block support such as ### or angle blocks shaped like an L will get upvoted by me :P and the most complete game of binary tetris (the most blocks like the original and rotation features) will win my happiness and a possible bounty up 50 rep.
• New blocks are added to the field in the top row, and one block cell must occupy the center column.
• Blocks descend towards the bottom row at a fixed rate. Blocks must descend even without user input.
• When blocks touch the bottom of the field or a lower block, they stop falling and are fixed in place. A new block is added.
• When all the columns in the row are filled with blocks, the row is emptied, and all the fixed blocks above drop down one row.
• The program must respond to keypresses. There must be 3 unique keys that perform the following functions
• shift current block left 1 column
• shift current block right 1 column
• shift current block down 1 row
• Each tweet may only have 140 characters. Using multi-byte characters that can be put in tweets is allowed.
• The rules for what can be in a tweet is simple. If you can tweet it you can use it.

• Interpreted languages follow the same rules. Each section must follow the specs. As long as no run time errors occur (and the rest is valid following the specs) your answer is valid Golfing Rules:
Because the original implementation was "tweetable", this challenge requires the same. Entries must be able to be transmitted as a series of tweets (lines of 140 characters or less).

• The first tweet must contain the name of the compiler/interpreter, the name of the program, and any command line arguments

• it will be saved as file "P0"
• The following N tweets must contain the program as a series of lines.
• Each tweet will be stored in a file with the name T<n>, where n is 1..N
• Each line will be added to the previous lines and compiled or interpreted. It must produce a valid object file or program.
• The program does not need to be functional until the last line is added.
• The program will be run in the following manner (pseudo-bash)

interp,prog,args = split P0 /\s/
touch $prog for file in ./T* do cat$prog file > $prog$interp $prog$args
die("FAIL") if \$? #detect error
done


The interpreter must be a commonly available executable program that does not already implement Tetris.

Scoring:
Fewest Tweets, including P0. Ties broken by largest number of spare characters (140 * num tweets - total character count).

Example Entries

chrome a.htm
<html><div id="output"></div></html>
<script>cool java script here</script>


Score = 3 (334 spare)

cc a.c ;a.out
main(){/*cool prog here*/}


Score = 2 (241 spare)

tetris


Score = 1 (134 spare) if it were legal, which it's not

# Special thanks

I was allowed to post this by Ashelly's consent here

• Tweets may contain UTF-8 characters. Is that true here as well (for example, can we stuff 400ish bytes into a single tweet using CJK characters?) – Robert Fraser May 18 '17 at 8:14
• @RobertFraser if you can type it into a tweet and send it then yes – Christopher May 18 '17 at 10:02
• If anything that can fit in a tweet is game, can we have newlines within each of our "tweets?" Line breaks are allowed within tweets. – notjagan May 18 '17 at 11:32
• @notjagan yes. It you can tweet it you can have it – Christopher May 18 '17 at 13:51
• If the challenge is going to be that way, you need to include an exact specification of which character sequences are allowed in a tweet. – feersum May 18 '17 at 14:01

# Python 3, Score of 5 Tweets (242 spare, counting P0)

-19 bytes thanks to Jonathan Allan!

The spare count does not take into account newlines from between tweets.

## Tweet 1 (Declaration, 12 bytes)

python3 t.py


## Tweet 2 (70 bytes)

import msvcrt as m,os;f=c=s=0;a=34636833;r=range;p=1<<32;t=30
while 1:


## Tweet 3 (129 bytes)

 if m.kbhit()and b"\xe0"==m.getch():p=[p>>(not(a|f<<1)&p),p,p<<(not(a<<4|f>>1)&p),p>>5-5*(bool(f&p>>5)or p<t)][ord(m.getch())-77]


## Tweet 4 (113 bytes)

 c+=1;print("\n".join("".join(".#"[1&(f|p)>>i*5+j]for j in r(5))for i in r(6))[::-1]);os.system("cls")
if c%t<1:


## Tweet 5 (134 bytes)

  if f&p>>5or p<t:s=~s;f|=p;p=2-s<<26
else:p>>=5
for i in r(0,t,5):
if f|31<<i==f:b=bin(f)[2:].zfill(t);f=int(b[:-i-5]+b[t-i:],2)


## Full Program (449 bytes)

import msvcrt as m,os;f=c=s=0;a=34636833;r=range;p=1<<32;t=30
while 1:
if m.kbhit()and b"\xe0"==m.getch():p=[p>>(not(a|f<<1)&p),p,p<<(not(a<<4|f>>1)&p),p>>5-5*(bool(f&p>>5)or p<t)][ord(m.getch())-77]
c+=1;print("\n".join("".join(".#"[1&(f|p)>>i*5+j]for j in r(5))for i in r(6))[::-1]);os.system("cls")
if c%t<1:
if f&p>>5or p<t:s=~s;f|=p;p=2-s<<26
else:p>>=5
for i in r(0,t,5):
if f|31<<i==f:b=bin(f)[2:].zfill(t);f=int(b[:-i-5]+b[t-i:],2)


Does some evil bit point hacking and stores the field and piece in two integers. I'll try and post an explanation soon.

Note: This only runs on Windows, but it could be switched to Linux through msvcrtgetch and "cls""clear". Additionally, character input doesn't work on Python's IDLE, so I'd recommend running it elsewhere.

• Wow well done! This short – Christopher May 18 '17 at 15:54
• Good work. \xe0 is four bytes not one so tweet 3 should be 130. You seem to have missed time.sleep(.1);c+=1 from tweet 4 and changed the order (I don't know if the order change is intentional) and again \n is two bytes not one, so it should be 134. – Jonathan Allan May 18 '17 at 18:31
• ...mind you it seems playable without the sleep on my machine. – Jonathan Allan May 18 '17 at 18:36
• You could also test c%10<1 and remove c=0. – Jonathan Allan May 18 '17 at 18:43
• @JonathanAllan Thanks for the suggestions! I was in a bit of a hurry when posting this so it seems I was somewhat careless with splitting the tweets. – notjagan May 18 '17 at 23:07

# JavaScript (4 Tweets / 343 317 bytes / 243 spare)

Not quite sure about the requirements of the header & Tweets format, so please advise if it needs correcting. Still a bit more can be shaved off I'm certain.

### Tweet 1 - P0 (11 bytes)

chrome a.js


## Tweet 2 (82 bytes)

a=y=z=j=0,onkeyup=b=>R((k=b.keyCode-40)?z*2*(d=k+3?k+1?1:.5:2)&65|j*d&a||(z*=d):0)


## Tweet 3 (126 bytes)

R=d=>{d||(!(!y||a&j>>5)||(y>25?a=0:(31^31&(a|=j)>>y||(a=a>>y+5<<y|a&-1>>>-y-5>>5),y=0)),y-=5),y>=0||(y=30,z=12/(new Date%3+1))


## Tweet 4 (98 bytes)

j=z<<y;for(o="",i=30;i--;)o+=1<<i&(a|j)?"#":"_",o+=i%5?"":"<br>";O.innerHTML=o},setInterval(R,300)


# Run it in JSFiddle: https://jsfiddle.net/CookieJon/7Lenhcge/

(Click on the output pane to provide focus for keyboard events)

• Please do not post partially completed or invalid answers to the question. As per this meta discussion this answer should be deleted until it complies with the spec outlined in the question – PunPun1000 May 19 '17 at 16:22
• @PunPun1000 My apologies. It's now completed and undeleted. – Bumpy May 21 '17 at 9:01
• No problem, I'll remove my downvote. Welcome to PPCG. – PunPun1000 May 21 '17 at 16:32