24 votes

2048-like array shift

Jelly, 10 9 8 bytes Œg+2/€UF TryItOnline or run all test cases How? ...
Jonathan Allan's user avatar
19 votes

2048-like array shift

Haskell, 47 57 50 bytes e#l|a:b<-l,e==a= -2*a:b|1<2=e:l map abs.foldr(#)[] Uses reduce (or ...
nimi's user avatar
  • 35.8k
16 votes
Accepted

Is it a good 2048 board?

Haskell, 21 bytes all$scanr1 max>>=(==) Try it online! Takes a list of columns, with empty spaces as 0.
xnor's user avatar
  • 145k
14 votes

2048-like array shift

Brain-Flak, 158 96 ...
Riley's user avatar
  • 11.7k
10 votes
Accepted

Create a simple 2048 game clone

APL (Dyalog APL), 153 150 167 156 155 151 bytes ...
Adám's user avatar
  • 30.2k
10 votes

Make a picture into a sliding puzzle

Mathematica, 246 bytes ...
JungHwan Min's user avatar
  • 13.8k
10 votes

Is it a good 2048 board?

05AB1E, 4 bytes €{íQ Try it online! Same as my other two answers. I promise this is my last one until others have answered :)
hyper-neutrino's user avatar
  • 42.4k
9 votes

2048-like array shift

PHP, 116 Bytes <?$r=[];for($c=count($a=$_GET[a]);$c-=$x;)array_unshift($r,(1+($x=$a[--$c]==$a[$c-1]))*$a[$c]);echo json_encode($r); or ...
Jörg Hülsermann's user avatar
9 votes

2048-like array shift

GNU sed, 41 38 37 Includes +1 for -r -3 Thanks to Digital Trauma -1 Thanks to seshoumara : s,(.*)(1+) \2\b,\1!\2\2!, t y,!, , Input and output are space ...
Riley's user avatar
  • 11.7k
9 votes

2048-like array shift

Python, 61 bytes def f(l):b=l[-2:-1]==l[-1:];return l and f(l[:~b])+[l[-1]<<b] The Boolean b checks whether the last ...
xnor's user avatar
  • 145k
9 votes

Is it a good 2048 board?

APL (Dyalog), 7 4 bytes Takes 4-by-4 matrix, using 0 for blanks, as argument. ⊢≡⌊⍀ Try it online! ⌊⍀ is the vertical ...
Adám's user avatar
  • 30.2k
8 votes

2048-like array shift

JavaScript (ES6), 68 bytes ...
sundar's user avatar
  • 81
8 votes

2048-like array shift

Perl, 41 bytes Includes +1 for -p Give input sequence on STDIN: shift2048.pl <<< "2 2 2 4 4 8 2" ...
Ton Hospel's user avatar
  • 14.9k
8 votes
Accepted

Solve the 15 Puzzle (the tile-sliding puzzle)

PyPy, 195 moves, ~12 seconds computation Computes optimal solutions using IDA* with a 'walking distance' heuristic augmented with linear conflicts. Here are the optimal solutions: ...
orlp's user avatar
  • 39.1k
8 votes

2048-like array shift

Retina, 32 \d+ $* r`\b\1 (1+)\b $1$1 1+ $.& r on line 3 activates right-to-left regex matching. And this means that the <...
Digital Trauma's user avatar
7 votes

2048-like array shift

Perl, 43 + 1 (-p) = 44 bytes Ton Hospel came up with 41 bytes answer, check it out! -4 thanks to @Ton Hospel! Edit : added ...
Dada's user avatar
  • 8,473
7 votes

2048-like array shift

Perl 5.10, 61 50 bytes (49 + 1 for flag) Thanks to Ton Hospel for saving 11 bytes! Regex-free solution, with -a flag: ...
Sake's user avatar
  • 901
7 votes

2048-like array shift

JavaScript (ES6),  68...64  58 bytes a=>(g=p=>(x=a.pop())|p?p?[...g(p^x?x:!(p*=2)),p]:g(x):a)() Try it online! Commented ...
Arnauld's user avatar
  • 192k
7 votes

Is it a good 2048 board?

Jelly, 4 bytes Ṣ€U⁼ Try it online! Input as an array of columns. Works with arbitrary-sized grids.
hyper-neutrino's user avatar
  • 42.4k
7 votes

Is it a good 2048 board?

R (+pryr), 23 bytes pryr::f(all(diff(x))<1) Which evaluates to the function function (x) all(diff(x)) < 1 Which ...
JAD's user avatar
  • 2,984
6 votes

2048-like array shift

05AB1E, 26 bytes D¥__X¸«DgL*ê¥X¸«£vy2ôO})í˜ Try it online! Generalized steps Reduce by subtraction to find where consecutive elements differ Reduce by ...
Emigna's user avatar
  • 53k
6 votes

Is it a good 2048 board?

Python 3, 42 bytes lambda l:all(x==sorted(x)[::-1]for x in l) Try it online! Same algorithm as my Jelly answer
hyper-neutrino's user avatar
  • 42.4k
5 votes

2048-like array shift

Java 7, 133 bytes Object f(java.util.ArrayList<Long>a){for(int i=a.size();i-->1;)if(a.get(i)==a.get(i-1)){a.remove(i--);a.set(i,a.get(i)*2);}return a;} ...
Geobits's user avatar
  • 19.7k
5 votes

2048-like array shift

Haskell, 56 bytes g(a:b:r)|a==b=a+b:g r|l<-b:r=a:g l g x=x r=reverse r.g.r
Damien's user avatar
  • 2,447
5 votes

2048-like array shift

Mathematica, 53 bytes Join@@(Reverse[Plus@@@#~Partition~UpTo@2]&/@Split@#)& Explanation Split@# Split the input ...
JungHwan Min's user avatar
  • 13.8k
5 votes

Is it a good 2048 board?

JavaScript, 37 bytes x=>''+x==x.map(v=>v.sort((x,y)=>y-x)) Call it like this: ...
tsh's user avatar
  • 34.7k
4 votes

2048-like array shift

Perl, 37 bytes Includes +4 for -0n Run with the input as separate lines on STDIN: perl -M5.010 shift2048.pl 2 2 2 4 4 8 2 ^D ...
Ton Hospel's user avatar
  • 14.9k
4 votes

2048-like array shift

PHP, 86 100 99 94 bytes for($r=[];$v=+($p=array_pop)($a=&$argv);)array_unshift($r,end($a)-$v?$v:2*$p($a));print_r($r); requires PHP 7.0; takes values from ...
Titus's user avatar
  • 14.7k
4 votes

Is it a good 2048 board?

C# (.NET Core), 71 bytes i=>{for(int n=3;++n<i.Length;)if(i[n]>i[n-4])return false;return true;} Try it online! The BORING way. Expects input flattened ...
Kamil Drakari's user avatar
4 votes

Is it a good 2048 board?

JavaScript, 34, 32 bytes v=>!v.some((x,i)=>i%4&&x>v[i-1]) Call by passing in a single array containing the first column, followed by the 2nd, ...
Grax32's user avatar
  • 1,302

Only top scored, non community-wiki answers of a minimum length are eligible