Dog Bunny Puzzle

Dog Bunny: A Cute Puzzle

Conrad Barski (@lisperati)‘s latest, Dog Bunny Puzzle, had jumped to #1 on HN. The puzzle presents the following somewhat minimalist interface:

The Dogs Bunny Puzzle

If you haven’t played it yet, you might want to go ahead and give it a shot first. Most people figured out the mechanics without any explicit instructions. A couple of things that may not be immediately clear, but typically discovered quickly within a few moves:

  • The edges are labeled with conditions, and can be used only if all of the said conditions are met.

  • The bunny or dog icons may sometimes cover up what kind of location they are at. You can drag them away to find out!

  • Multiple animals can occupy the same spot at a time.

  • It is possible to get into a dead end, a situation from where no legal moves are possible. In the verison of the game that is available at the time of this writing, the game offers no sign that you might be in this situation. This may however change.

After winging it on the puzzle, several questions seemed natural:

So the last question may strike you as a bit left-field, but that’s what I’m going to ramble about for the rest of this post :) It turns out that the answer is in the affirmative, and here is a lovely reduction by @lokshtanov showing as much.

The Reduction

Let’s just set up the game as a computational problem just to be sure that we agree on the abstraction. In fact, we’ll be working with a simpler version that we will call BunnyCarrot.

We are going to show that BunnyCarrot is NP-complete by reducing from 3SAT. So let ϕ:={C1,,Cm}\phi := \{C_1, \ldots, C_m\} be a collection of mm 3SAT clauses over variables {x1,,xn}\{x_1, \ldots, x_n\}. The reduced instance of BunnyCarrot corresponding to ϕ\phi looks like this:

A cartoon sketch of the reduced instance of BunnyCarrot from 3SAT.

What we have here is the following in terms of the structure of graph:

  • a path XX on m+2m+2 vertices, with the left most vertex in BB and the rightmost one in CC;

  • a pair of vertices (ui,vi)(u_i,v_i) for every i[n]i \in [n], and an edge between them, where all the uiu_i‘s are in BB’ — the vertex uiu_i represents the literal xix_i while the vertex viv_i represents the literal xi\overline{x_i};

  • a pair of vertices pp and qq in CC, with pp adjacent to all uiu_i‘s and qq adjacent to all viv_i‘s.

Now here be the instructions associated with the edges:

  • the edge to the \ell-th vertex on XX is active only if there is a bunny on at least one of the literals present in the clause C1C_{\ell-1};

  • the edges between uiu_i and viv_i are active only when there is a bunny on the leftmost vertex of XX; and

  • finally, the edges incident on pp and qq are active only when there is a bunny on the rightmost vertex of XX.

The Forward Direction

We first claim that we can “win” this game if ϕ\phi has a satisfying assignment. Indeed, let τ:{x1,,xn}{0,1}\tau: \{x_1,\ldots,x_n\} \rightarrow \{0,1\} be a truth assignment that satisfies all the clauses of ϕ\phi. Then:

  1. If τ(xi)=0\tau(x_i) = 0, move the bunny on uiu_i to viv_i.

  2. Move the bunny on the leftmost vertex of the path XX to the rightmost vertex: note that all edges are active because τ\tau is a satisfying assignment.

  3. Move all bunnies on uiu_i‘s to pp and those on viv_i‘s to qq.

The Backward Direction

Now suppose there is a winning sequence of moves σ\sigma. We will show that we can extract from this sequence a satisfying assignment for ϕ\phi, which will firmly establish the equivalence of the generated instance of BunnyCarrot with the OG hard instance ϕ\phi.

Note that to begin with, all the blue edges are inactive. Now, in the sequence σ\sigma, let us say that a step is key if it involves a bunny moving along the first edge of the path XX and critical if it involves a bunny moving along the last edge of the path XX.

Suppose the \ell-th step is the first critical step in σ\sigma. Further, suppose that the tt-th step is the last key step to occur before the \ell-th step. Notice that there must be at least one key step before a critical step — we must begin before we can end :)

Now, for all steps after the tt-th step and before the \ell-th step, note that edges incident to uiu_i and viv_i are inactive for all i[n]i \in [n]. This implies that every step between the tt-th and \ell-th steps involves a bunny moving along XX, and in particular, every edge in XX is crossed at least once in this phase of the game.

Let us note the positions of the bunnies who are on the uiu_i‘s and viv_i‘s after the tt-th step is executed. Observe that this naturally translates to an assignment on the variables as follows:

τ(xi)={1if uiB,0if viB. \begin{equation*} \tau(x_i) = \begin{cases} 1 & \text{if } u_i \in B,\\ 0 & \text{if } v_i \in B. \end{cases} \end{equation*}

We argue that τ\tau must in fact be a satisfying assignment.

Assume to the contrary: suppose some clause CkC_k is, in fact, not satisfied by τ\tau.

Then, we claim that the edge connecting the kk-th and (k+1)(k+1)-th vertices is not active.

As an example, suppose Ck={x1,x2,x3}C_k = \{x_1,x_2,\overline{x_3}\}. Since τ\tau does not satisfy CkC_k, it must be the case that:

  • τ(x1)=0\tau(x_1) = 0 — and hence there is a bunny on v1v_1;
  • τ(x2)=0\tau(x_2) = 0 — and hence there is a bunny on v2v_2;
  • τ(x3)=1\tau(x_3) = 1 — and hence there is a bunny on u3u_3.

However, the condition for the edge to the (k+1)(k+1)-th vertex on XX to be active is simply that there is a bunny present on at least one of the literals present in the clause CkC_{k}, i.e, one of u1u_1, u2u_2 or v3v_3. However, because of the structure of the graph, and the fact that all edges incident on pp and qq are inactive at all times before the first critical step, observe that:

  • If there is a bunny on v1v_1, there is no bunny on u1u_1.
  • If there is a bunny on v2v_2, there is no bunny on u2u_2.
  • If there is a bunny on u3u_3, there is no bunny on v3v_3.

By our assumption that τ\tau falsifies CkC_k, all the premises above are true! So there is an edge on the path XX that is not active between the tt-th and \ell-th steps, which violates our understanding that every edge was crossed between these steps. This is a contradiction, and hence τ\tau must indeed be a satisfying assignment.

I’ll just remark here that this construction can be modified so that every vertex in the graph has constant degree, and there is only one vertex in CC. It can also be modified to change the “or” condition on the edges to an “and”, by simply separating the conditions out along multiedges.

Food for thought

Here are some more questions :)

Important

  1. What’s the complexity of this game when the underlying graph has some simple structure (e.g, a tree)?

  2. Does the problem get harder if we introduce attacking entities like wolves?

  3. Can we come up with an algorithm that runs in polynomial time on instances where there is a valid winning sequence of constant length?

  4. Is the problem hard even for a constant number of bunnies?

PS. Here’s a sketch of a slighty different reduction from vertex cover. Thanks again to Daniel for sharing the reduction described here! Comments welcome here, or continue the conversation on Twitter!