Skip to content

Instantly share code, notes, and snippets.

@netvarun
netvarun / 2048-as-a-service-perl
Created April 1, 2014 09:33
2048-as-service perl one-liner
perl -e 'my $host = "http://2048.semantics3.com/hi/";my $cmd = "curl --silent -L $host"."start";my $output = `$cmd`;my $session_id = $output;$session_id=~s/.*?ID:\s(\w+).*/$1/si;my %keyMap = ( 'w' => 0, 'd' => 1, 's' => 2, 'a' => 3);print STDERR $output,"\n";while(1) { print STDERR "Input (w - up, a - left, d - right, s - down):\n"; my $userInput = <STDIN>; chomp ($userInput); if(defined($keyMap{$userInput})) { $userInput = $keyMap{$userInput}; } else { print STDERR "Invalid move.. w - up, a - left, d - right, s - down\n"; next; } my $cmd = "curl --silent $host"."state/$session_id/move/$userInput"; my $output = `$cmd`; print STDERR "\n$output\n"; if($output=~/Message:/si) { exit(0); }}'

Keybase proof

I hereby claim:

  • I am netvarun on github.
  • I am netvarunog (https://keybase.io/netvarunog) on keybase.
  • I have a public key ASDK4M9YOd5V98M67FGGdhzxj9F6v6F0XWSN9mYJAvE96wo

To claim this, I am signing this object: