Last active
July 26, 2023 22:15
-
-
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/
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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[]} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Generates 2s only… :C