Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
Tiny 2048 in C!
M[16],X=16,W,k;main(){T(system("stty cbreak")
]=l:0,++k,W|=2*!l,l=0);}w(d,i,j){return d?w(d
puts(""))printf(M[i]?"%4d|":" |",M[i]);W-2
||read(0,&k,3)|T(s (1,K[(k>>X)%4]));}//[2048]

This is awesome! Could you also post the unminified code?

gvt commented Apr 5, 2014

LOL. I am impressed. You could get a job at Twitter with these algorithm skills. (I'm assuming it works haha)

bronson commented Apr 5, 2014

Very nice! It works great. If someone takes the time to reformat the code, post it in another gist? It would be nice to see what makes it tick.

m1dnight commented Apr 5, 2014

Just when I kicked my addiction..
Reformated...please help to reformat it further and add comments in the code so that it becomes self explanatory.

jcubic commented Apr 5, 2014

gcc give warnings but it compile and work. Nice.

This is very impressive! So is your tiny Conways game of life, brilliant!

Impressive, but it lets me execute invalid moves.

kr094 commented Apr 5, 2014

This is great, works fine in devcpp on windows.

akarpus commented Apr 5, 2014

Quite a few warnings from gcc but seems to work fine.... good job!

ldong commented Apr 5, 2014


srini156 commented Apr 5, 2014

This is super cool. Great job :)

happybot commented Apr 5, 2014

Obfuscated. I mean cool.

seanoop commented Apr 5, 2014

我擦, 太niubility了

seanoop commented Apr 5, 2014

我擦, 太niubility了

seanoop commented Apr 5, 2014

我擦, 太niubility了

seanoop commented Apr 5, 2014

我擦, 太niubility了

seanoop commented Apr 5, 2014

我擦, 太niubility了

This is great! One issue is that when you execute an invalid move (i.e. a move that should not cause anything to move) a new tile is spawned.

This is by far the coolest implementation of the 2048 game. Pure Awesome!

sebm commented Apr 5, 2014

works on mac. nice!

Just played the game on terminal. Nice one dude.

blockjon commented Apr 5, 2014


Great, nice work. hughrawlinson is correct though

chc2259 commented Apr 6, 2014


cheergo commented Apr 6, 2014

so niubility.

awesome and great.

jiashuw commented Apr 6, 2014

This is legit.

awesome work

zhouqiji commented Apr 6, 2014


HalZf commented Apr 6, 2014


freelrvy commented Apr 6, 2014


hemoely commented Apr 6, 2014

I'm slow ╮(╯▽╰)╭

ggyegou commented Apr 6, 2014



eastlhu commented Apr 6, 2014


aegiryy commented Apr 6, 2014

very excellent job!

crimx commented Apr 6, 2014

Nice work! Very impressive!

Reformatted code.

sheimi commented Apr 6, 2014


ryc111 commented Apr 6, 2014


zerob13 commented Apr 6, 2014


TankCool commented Apr 6, 2014


ezel commented Apr 6, 2014

Good Job!

ezel commented Apr 6, 2014

Good Job!

pyguy commented Apr 6, 2014

Nice Job Dude :)

dazhao commented Apr 6, 2014

why read(0,&k,3)? the arrow keys only need 2bytes.

icylord commented Apr 6, 2014

good job !!!

weedge commented Apr 6, 2014


balaziks commented Apr 6, 2014

There is a small bug in this implementation:
When there is nothing to move in some direction but I press the arrow to that direction it'll spawn new tile. Original 2048 wouldn't let me do this.

After arrow-down:

k1ll4m3 commented Apr 6, 2014

good job!

sadid commented Apr 6, 2014

it has a warning (gcc) but works...amazing

djlinks commented Apr 6, 2014 niubility

amad commented Apr 6, 2014

loool fantastic :))

yifanes commented Apr 7, 2014



kunahe commented Apr 7, 2014


armagad commented Apr 7, 2014

It is more like horse shoes than golf.

Maybe if there was some code hand grenading contest.

moham commented Apr 8, 2014

WoW 8O
very impressive!

xdqi commented Apr 11, 2014

Compiled successfully using MinGW and VC11 but unusable.

Nice job


Nice job. +1




jagosw commented Apr 23, 2016

This is awsome, works well on mac!!

ironmaniiith commented Jun 19, 2016

I tried to code 2048 in c in my 1st year of college (right now in 2nd) and I did that with around 700 lines.
If you were a girl, I would have proposed you ( wouldn't care if rejected though 😜 ).
Seriously HATS OFF DUDE.

Just saw your other works as well.
You are not normal human, you are GOD.
Please tell me what is your daily routine.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment