2048 is NP-Complete. Ahmed Abdelkader Aditya Acharya Philip Dasler. Theorem 1 2048-GAME is NP-Complete.

Similar documents
2048 Without New Tiles Is Still Hard

The Theory of Tetris

Introduction to Logic in Computer Science: Autumn 2006

The Hardness of the Lemmings Game, or Oh no, more NP-Completeness Proofs

CSC 373: Algorithm Design and Analysis Lecture 16

Welcome to... Problem Analysis and Complexity Theory , 3 VU

NP-complete? NP-hard? Some Foundations of Complexity. Prof. Sven Hartmann Clausthal University of Technology Department of Informatics

TEACHER S GUIDE TO RUSH HOUR

NP-Completeness and Cook s Theorem

Sue Fine Linn Maskell

SMART NOTEBOOK 10. Instructional Technology Enhancing ACHievement

Diagonalization. Ahto Buldas. Lecture 3 of Complexity Theory October 8, Slides based on S.Aurora, B.Barak. Complexity Theory: A Modern Approach.

On the Unique Games Conjecture

15-251: Great Theoretical Ideas in Computer Science Anupam Gupta Notes on Combinatorial Games (draft!!) January 29, 2012

Introduction Solvability Rules Computer Solution Implementation. Connect Four. March 9, Connect Four

Complexity Theory. Jörg Kreiker. Summer term Chair for Theoretical Computer Science Prof. Esparza TU München

Microsoft Excel 2010 Charts and Graphs

Mathematical Induction

Sudoku puzzles and how to solve them

Introduction to NP-Completeness Written and copyright c by Jie Wang 1

OHJ-2306 Introduction to Theoretical Computer Science, Fall

Ian Stewart on Minesweeper

VLOOKUP Functions How do I?

The resulting tile cannot merge with another tile again in the same move. When a 2048 tile is created, the player wins.

CATIA Drafting TABLE OF CONTENTS

Creating Drawings in Pro/ENGINEER

Exponential time algorithms for graph coloring

P versus NP, and More

Boulder Dash is NP hard

Offline 1-Minesweeper is NP-complete

Near Optimal Solutions

Lecture 7: NP-Complete Problems

One pile, two pile, three piles

Guessing Game: NP-Complete?

Problem Set 7 Solutions

Excel 2007 A Beginners Guide

Graph Theory Problems and Solutions

CONSTRUCTING SINGLE-SUBJECT REVERSAL DESIGN GRAPHS USING MICROSOFT WORD : A COMPREHENSIVE TUTORIAL

Hexagonal Pyramid in Google SketchUp

ON THE COMPLEXITY OF THE GAME OF SET.

Bounded-width QBF is PSPACE-complete

The Classes P and NP

An Introduction to The A* Algorithm

Data Structures Fibonacci Heaps, Amortized Analysis

Excel -- Creating Charts

Communicate: In Print

To launch the Microsoft Excel program, locate the Microsoft Excel icon, and double click.

LAMC Beginners Circle: Parity of a Permutation Problems from Handout by Oleg Gleizer Solutions by James Newton

Three daily lessons. Year 5

10 th POLISH SUDOKU CHAMPIONSHIP INSTRUCTION BOOKLET. February 22, 2015 IMPORTANT INFORMATION:

The Pointless Machine and Escape of the Clones

Using VLOOKUP to Combine Data in Microsoft Excel

Excel 2003 A Beginners Guide

Geometric Transformations

BOOLEAN ALGEBRA & LOGIC GATES

Android Basic XML Layouts

Tetris is Hard: An Introduction to P vs NP

An Australian Microsoft Partners in Learning (PiL) Project

Creating Maze Games. Game Maker Tutorial. The Game Idea. A Simple Start. Written by Mark Overmars

Some Minesweeper Configurations

Pigeonhole Principle Solutions

Excel 2007: Basics Learning Guide

Ready, Set, Go! Math Games for Serious Minds

CHAPTER 7 INTRODUCTION TO SAMPLING DISTRIBUTIONS

Handout #1: Mathematical Reasoning

ADDING and/or DELETING PIN NUMBERS (Plus other simple programming commands) in My DK-16 or DK-26 DIGITAL KEYPAD

Introduction to Algorithms. Part 3: P, NP Hard Problems

Tutorial 8. NP-Complete Problems

The Butterfly, Cube-Connected-Cycles and Benes Networks

Page 1. CSCE 310J Data Structures & Algorithms. CSCE 310J Data Structures & Algorithms. P, NP, and NP-Complete. Polynomial-Time Algorithms

The Chinese Remainder Theorem

On-line choosability. Grzegorz Gutowski

Theoretical Computer Science (Bridging Course) Complexity

Easy Calculations in Excel

Arrangements And Duality

VISUAL ALGEBRA FOR COLLEGE STUDENTS. Laurie J. Burton Western Oregon University

arxiv: v1 [cs.cg] 15 Sep 2014

ABOUT THIS DOCUMENT ABOUT CHARTS/COMMON TERMINOLOGY

2004 Solutions Ga lois Contest (Grade 10)

Midterm Practice Problems

Kenken For Teachers. Tom Davis June 27, Abstract

PowerPoint 2007 Basics Website:

Using Excel to find Perimeter, Area & Volume

Ch. 13.2: Mathematical Expectation

Probability. Section 9. Probability. Probability of A = Number of outcomes for which A happens Total number of outcomes (sample space)

Logi Ad Hoc Reporting System Administration Guide

Chapter. NP-Completeness. Contents

Transportation Polytopes: a Twenty year Update

Lesson #13 Congruence, Symmetry and Transformations: Translations, Reflections, and Rotations

Mathematical Research Letters 1, (1994) MAPPING CLASS GROUPS ARE AUTOMATIC. Lee Mosher

How To Create A View Frame In 3D

Efficient Fault-Tolerant Infrastructure for Cloud Computing

Hands-On Math Algebra

A HYBRID APPROACH FOR AUTOMATED AREA AGGREGATION

Qualification Specification

Department of Physics and Geology The Elements and the Periodic Table

A Working Knowledge of Computational Complexity for an Optimizer

E XPLORING QUADRILATERALS

GRAPH THEORY LECTURE 4: TREES

Note: To increase your bet by another amount, select another chip from the bottom right of the game panel.

Transcription:

CG:YRF, Eindhoven, The Netherlands, June 22-25, 2015 2048 is NP-Complete Ahmed Abdelkader Aditya Acharya Philip Dasler Abstract 2048 is a single-player online puzzle game that went viral in March 2014. The game is played on a 4 4 board by sliding around and merging equal valued tiles to create tiles of higher value. The player wins by creating the 2048 valued tile, hence the name. We study the complexity of a slightly adapted version and prove that a number of natural decision problems turn out to be NP-Complete. We reduce from 3SAT and implement our reduction as an online game. 1 Introduction Each turn, the player picks a move from {,,, } to slide all tiles on the board. Tiles slide as far as possible in the chosen direction until they hit either another tile or an edge of the board. When a sliding tile runs into a stationary one of equal value, they merge into a tile of double that value. Trailing tiles following a tile that just merged continue to slide uninterrupted and may merge among themselves as they come to rest one after the other. However, newly merged tiles cannot merge further in the same move. After each move, a 2 or 4 tile is generated in one of the empty cells. The player wins when a 2048 tile is created, hence the name of the game. Otherwise, the player loses when the board is full and no merges can be performed. 2048 combines features from two families of games: Candy Crush Saga [1] and PushPush [2]. A more detailed draft of this work appears in [3], where we also discuss the attempt in [4]. The interactive gadgets and playable reduction can be accessed at [5]. 1.1 Adaptations and Problem Definition We adapt the original 2048 as follows: (1) The input encodes the complete board configuration and no new tiles are generated. (2) The board is a rectangular grid of arbitrary size. In this paper, we are primarily concerned with the following decision problem: Definition 1 (2048-GAME) Given a configuration of tiles on an m n board, is it possible to obtain a tile of value 2048? (More generally, 2 k with k 8.) University of Maryland, College Park, akader@cs.umd.edu University of Maryland, College Park, acharya@cs.umd.edu University of Maryland, College Park, daslerpc@cs.umd.edu [6] presented a proof of membership in NP, that applies to 2048-GAME. The crucial piece is to bound the number of moves between two consecutive merges. Using a canonical orientation, all moves are interpreted as flips of the board, which send tiles along orbits of O(mn) length. A pair of tiles that end up merging requires no more than LCM(O(mn), O(mn)) = O(m 2 n 2 ) moves. In this paper, we prove NP-hardness by a reduction from 3SAT and obtain the main result. Theorem 1 2048-GAME is NP-Complete. 2 Reduction from 3SAT Given an instance of 3SAT with n variables and m clauses, we produce an instance of 2048-GAME. The board is filled using a 2-4 lattice to provide a rigid base for placing gadgets and planning their movements. We allow no merges using lattice tiles, which requires preserving their parity. This confines all merges to multiples of 2 2 blocks. We use row and column to denote a 2-row and a 2-column, respectively. Displacers: These are the building blocks of all gadgets which allow us to communicate signals across the board. They come in two main forms: horizontal D and vertical D T. Typically, a displacer starts in an inactive state where the middle 2 2 block, highlighted below, is shifted perpendicularly to the displacer s direction. An inactive displacer cannot merge, by any move sequence, before it is activated. The only way to activate it is to use another properly aligned displacer to engage its middle block. Collapsing tiles in a displacer shrinks it to a 2 2 block, which results in a parity-preserving pull in a row or a column. [ ] 8 8 16 16 D = 32 32 64 64 Variable Gadget: Each variable is represented by two horizontal displacers on the same row. This enables variables to move the portion of its row between their two displacers to the right or left. We enforce the assignment of variables in the order of their indices. A variable is assigned T or F using a or move, respectively. The displacers of x 1 come activated in the initial configuration to allow the game to start. No matter how variable x i is assigned, the connector displacers in its row get activated and allow x i+1 on top of it to be activated by a move in the following turn. This is an abstract of a presentation given at CG:YRF 2015. It has been made public for the benefit of the community and should be considered a preprint rather than a formally reviewed paper. Thus, this work is expected to appear in a conference with formal proceedings and/or in a journal.

4 th Computational Geometry Young Researchers Forum, 2015 x aux Clauses Key-Lock x 2 x 2 x 1 Literals x 1 x 3 x 3 x 0 x 0 Figure 1: Annotated reduction. Only x 0 is active. We apply log 2 and hide paddings to help display a large board. Clause Gadget: Literals are encoded using a similar mechanism to the connectors in the variable gadget. but are only activated by the appropriate assignment. When a literal is activated, it allows a pull in the clause s column to effectively satisfy this clause. Each satisfied clause eventually contributes one horizontal displacer by providing its middle block. Key-Lock Gadget: To check that all clauses are satisfied, it helps to arrange for a special event to happen only after all variables have been assigned. To achieve this, an auxiliary variable x aux = x n+1 activates the lock portion of this gadget. Satisfying all clauses corresponds to using the correct key. Together, the activated key-lock gadget is a sequence of displacers that can activate a unique displacer with two 1024 tiles. Collapsing that unique displacer creates the desired 2048 tile. 2.1 Properties of the Reduction Size: As variables are stacked on top of each other all the way up to x aux and the key-lock gadget, the number of rows is O(n). Then, each variable has to activate the connectors to the next variable. We get a pyramid shape with variable displacers on both sides and literals in the middle, plus the unique displacer taking up 2(m + 1) columns far to the right, for a total of O(m+n) columns. Gaps and Padding: A gap is created iff two tiles merge. The construction guarantees that gaps are only created near the edges of the board and accumulate at the corners. To make sure such gaps do not result in undesired shifts within the core, it has to be surrounded by enough padding. As the number of active gadgets is O(m + n) and each gadget contributes a constant number of gaps, a padding of O(m+n) thickness suffices. Game Play: When no merges happen, two consecutive moves in opposite directions leave the board unchanged e.g. [,, ] is effectively reduced to [ ]. Effective moves alternate between horizontal and vertical. The alternation accumulates newly created gaps, resulting from the merge, at the corners so the decision encoded by the previous move cannot be altered. Furthermore, any row or column may witness merges during at most one turn. In particular, clause columns cannot experience more than one pull. This implies consistent assignments. Finally, moves are useless since they must be canceled or otherwise the player cannot win. Hardness: Aligning the two 1024 tiles requires a 2m shift, which only satisfied clauses can provide with each satisfied clause contributing 2. Hence, the 2048 tile can be created iff the 3SAT instance is satisfiable. References [1] Luciano Gualà, Stefano Leucci, and Emanuele Natale. Bejeweled, Candy Crush and other Match-Three Games are (NP-)Hard. CoRR, abs/1403.5830, 2014. [2] Erik D. Demaine, Martin L. Demaine, and Joseph O Rourke. PushPush is NP-hard in 2D. CoRR, cs.cg/0001019, 2000. [3] Ahmed Abdelkader, Aditya Acharya, and Philip Dasler. On the complexity of slide-and-merge games. CoRR, abs/1501.03837, 2015. [4] Rahul Mehta. 2048 is (PSPACE) Hard, but Sometimes Easy. CoRR, abs/1408.6315, 2014. [5] Ahmed Abdelkader. 2048 gadgets. http://cs.umd.edu/ ~akader/projects/2048/index.html. [6] Christopher Chen. 2048 is in NP. http://blog. openendings.net/2014/03/2048-is-in-np.html.

CG:YRF, Eindhoven, The Netherlands, June 22-25, 2015 x 0 x 1 x 2 x 3 x aux Clauses Literals x 3 Figure 2: Annotated reduction of a given boolean formula. x 2 Key-Lock x 1 x 0

4 th Computational Geometry Young Researchers Forum, 2015 Figure 3: Board(0): Initial configuration.

CG:YRF, Eindhoven, The Netherlands, June 22-25, 2015 Figure 4: Board(1): move( ). x0 assigned T.

4 th Computational Geometry Young Researchers Forum, 2015 Figure 5: Board(2): move( ). c2 satisfied. x0 fixed to T. x1 activated.

CG:YRF, Eindhoven, The Netherlands, June 22-25, 2015 Figure 6: Board(3): move( ). x1 assigned F.

4 th Computational Geometry Young Researchers Forum, 2015 Figure 7: Board(4): move( ). c0 satisfied. x1 fixed to F. x2 activated.

CG:YRF, Eindhoven, The Netherlands, June 22-25, 2015 Figure 8: Board(5): move( ). x2 assigned F.

4 th Computational Geometry Young Researchers Forum, 2015 Figure 9: Board(6): move( ). c1 satisfied. x2 fixed to F. x3 activated.

CG:YRF, Eindhoven, The Netherlands, June 22-25, 2015 Figure 10: Board(7): move( ). x3 assigned T.

4 th Computational Geometry Young Researchers Forum, 2015 Figure 11: Board(8): move( ). x3 fixed to T. xaux activated.

CG:YRF, Eindhoven, The Netherlands, June 22-25, 2015 Figure 12: Board(9): move( ). Key-lock sequence initiated.

4 th Computational Geometry Young Researchers Forum, 2015 Figure 13: Board(10): move( ). Key-lock ready.

CG:YRF, Eindhoven, The Netherlands, June 22-25, 2015 Figure 14: Board(11): move( ). All clauses satisfied? Unlock.

4 th Computational Geometry Young Researchers Forum, 2015 Figure 15: Board(12): move( ). Win.