Skip to content

Instantly share code, notes, and snippets.

@Nakilon
Last active July 26, 2023 22:15
Show Gist options
  • Save Nakilon/10571155 to your computer and use it in GitHub Desktop.
Save Nakilon/10571155 to your computer and use it in GitHub Desktop.
2048 golfed to 379 chars in Ruby by Nakilon for http://www.reddit.com/r/tinycode/comments/22wozn/
require"io/console"
_=[[_]*4]*4
t=->{_=_.transpose}
r=->{_.map! &:reverse}
f=->{_=_.map{|_|_=(_*?\s).gsub(/\b(\d+) +\1\b/){|_|_.to_i*2}.split;_[3]||=p;_}}
f[]
loop{(0while _[i=rand(4)][j=rand(4)];_[i][j]=[*[?2]*9,?4].sample)if$n!=_*?_
system"clear"
_.map{|_|puts"%5s"*4%_}
(c=STDIN.getch)[?q]|0
$n=_*?_
c==?s&&t[]+r[]+f[]+r[]+t[]
c==?d&&r[]+f[]+r[]
c==?w&&t[]+f[]+t[]
c==?a&&f[]}
@balaziks
Copy link

Generates 2s only… :C

@Nakilon
Copy link
Author

Nakilon commented Apr 14, 2014

@balast, fixed

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