Skip to content

Instantly share code, notes, and snippets.

@justecorruptio
Created April 9, 2014 08:39
Show Gist options
  • Select an option

  • Save justecorruptio/10242450 to your computer and use it in GitHub Desktop.

Select an option

Save justecorruptio/10242450 to your computer and use it in GitHub Desktop.

Revisions

  1. justecorruptio created this gist Apr 9, 2014.
    5 changes: 5 additions & 0 deletions 2048.pl
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,5 @@
    sub Y{$p=$_;for$i(1..4){$p=join'',map{substr+($k&&$k-$i?$p:join'',map{s/@//g;s
    /(.)\1/++($a=$1)/eg;$_|'@'x4}$p=~/.{4}/g),3+$_%4*4-($_/4|0),1}0..15}$p}$_='@'x
    16;for(`stty cbreak`;print"\e[2J\e[H";$_=Y map{$k=index+JDACB,getc}0..2){$k=0;
    1until$r=0|rand 16,!/@/||s/(?<=^.{$r})@/rand>.1?A:B/e;printf'%4s|%s',/\w/&&1<<
    (ord)-64,++$g%4?'':$/for/./g;last if$e=WIN x/K/||Y!~/@/&&LOSE}print$e # [2048]