Watch Your Step!

Let G G be a rectangular grid of unit squares with 3 rows and 8 columns. How many self-avoiding walks are there from the bottom left square of G G to the top left square of G G ?

Details and assumptions

A self-avoiding walk on a rectangular grid of unit squares is a sequence of moves between horizontally or vertically adjacent squares that does not visit the same square more than once.

The walk does not need to touch all the squares of G G .

Since the grid has 3 rows, the top left and bottom left squares have exactly one square between them.


The answer is 984.

This section requires Javascript.
You are seeing this because something didn't load right. We suggest you, (a) try refreshing the page, (b) enabling javascript if it is disabled on your browser and, finally, (c) loading the non-javascript version of this page . We're sorry about the hassle.

5 solutions

Fatik Redy Hanif
May 20, 2014

Let s i , j s_{i,j} be the unit square at column i i and row j j (So we want to go from s 1 , 3 s_{1,3} to s 1 , 1 s_{1,1} ). And define a n a_n be the number of ways to reach s 1 , 1 s_{1,1} from s 1 , 3 s_{1,3} that contains rightward movement exactly n 1 n-1 times (note that this is equivalent to the maximum column being reached is column n n ). Let b n b_n be the number of ways to reach s 1 , 1 s_{1,1} from s 1 , 3 s_{1,3} that contains rightward movement exactly n 1 n-1 times and passes through s 1 , 2 s_{1,2} . Let c n c_n be the complement of b n b_n in a n a_n , so a n = b n + c n a_n = b_n+c_n .

Note that, the first step of c n c_n must be s 1 , 3 s 2 , 3 s_{1,3}\rightarrow s_{2,3}\rightarrow\ldots and the last step must be s 2 , 1 s 1 , 1 \ldots\rightarrow s_{2,1}\rightarrow s_{1,1} . Therefore it is the same as the number of ways to go from s 2 , 3 s_{2,3} to s 2 , 1 s_{2,1} , by only moving right exactly n 2 n-2 times, which is a n 1 a_{n-1} . So c n = a n 1 c_n=a_{n-1} where c 1 : = 0 c_1:=0

For b n b_n , we have b 1 = 1 b_1=1 and if n > 1 n>1 then either we pass through s 1 , 2 s_{1,2} in the first step or in the last step exclusively, that is, either s 1 , 3 s 1 , 2 s 2 , 2 s_{1,3}\rightarrow s_{1,2}\rightarrow s_{2,2}\rightarrow\ldots (call it p n p_n ) or s 2 , 2 s 1 , 2 s 1 , 1 \ldots\rightarrow s_{2,2}\rightarrow s_{1,2}\rightarrow s_{1,1} (call it q n q_n ). By reflection on horizontal line, we see that p n = q n p_n=q_n which implies b n = 2 p n b_n=2p_n .

Now for 1 < i n 1<i\leq n , let r i r_i denotes the number of ways in p n p_n that move downward for the first time at column i i (actually r n r_n represents the case where it doesn't go down at all, which there is only one way to do that). Note that the first i + 2 i+2 steps in r i r_i is s 1 , 3 s 1 , 2 s 2 , 2 s 3 , 2 s i , 2 s i , 3 s i + 1 , 3 s_{1,3}\rightarrow s_{1,2} \rightarrow s_{2,2}\rightarrow s_{3,2}\rightarrow\ldots\rightarrow s_{i,2} \rightarrow s_{i,3}\rightarrow s_{i+1,3}\rightarrow\ldots and so it is the same as the number of ways to reach s i + 1 , 1 s_{i+1,1} from s i + 1 , 3 s_{i+1,3} by moving right n i 1 n-i-1 times (because we have moved right i i times), which is a n i a_{n-i} . So by defining a 0 = 1 a_0=1 we have p n = i = 2 n r i = i = 0 n 2 a i p_n = \sum_{i=2}^nr_i = \sum_{i=0}^{n-2}a_i and so b n = 2 i = 0 n 2 a i b_n=2\sum_{i=0}^{n-2}a_i .

Combining above results, we have a n = b n + c n = 2 i = 0 n 2 a i + a n 1 a_n = b_n + c_n = 2\sum_{i=0}^{n-2}a_i + a_{n-1} , which implies a n = ( a n 1 + a n 2 ) + a n 1 = 2 a n 1 + a n 2 a_n = (a_{n-1}+a_{n-2})+a_{n-1} = 2a_{n-1}+a_{n-2} . And so since a 1 = 1 a_1=1 and a 2 = 3 a_2=3 , we have a 3 = 7 , a 4 = 17 , a 5 = 41 , a 6 = 99 , a 7 = 239 , a 8 = 577 a_3=7, a_4=17, a_5=41, a_6=99, a_7=239, a_8=577 . What we are looking for is n = 1 8 a n = 1 + 3 + 7 + 17 + 41 + 99 + 239 + 577 = 984 \sum_{n=1}^8 a_n = 1+3+7+17+41+99+239+577 = 984 .

[Edits by Aldrian]

Quang Minh Bùi
Aug 5, 2013

We consider that each column can be in 3 states:

  • State 1: The output pins (the right side of column) is located at the top and the bottom squares.
  • State 2: The output pins is located at the middle and a top or bottom squares.
  • State 3: The output pins is none (the path is closed in this column).

Note : since the grid has 3 rows, and the path is begin from the first column (the left most), there are only two output pins each column.

  • State 1 can lead to one case of state 1 and state 3, two cases of state 2.
  • State 2 can lead to one case of each state.
  • State 3 can only lead to state 3 (the path has been closed).

Then, use the stochastic matrix to solve this Markov chain:

A = [ 1 2 1 1 1 1 0 0 1 ] A = \begin{bmatrix} 1 & 2 & 1 \\ 1 & 1 & 1 \\ 0 & 0 & 1 \end{bmatrix}

Initially, the input state is state 1 (the path ends at the top and bottom left squares) and the last state must be state 3 (the path must be closed at last). So the solution of this problem is:

( A 8 ) 1 , 3 = 984 (A^{8})_{1,3} = 984

Note : you only need to track A 1 , 1 n , A 1 , 2 n , A 1 , 3 n A_{1,1}^n, A_{1,2}^n, A_{1,3}^n rather than whole matrix when powering.

What an interesting way to think about the problem. Thank you for your solution Quang.

Jiao Wang - 7 years, 10 months ago

Log in to reply

Thanks for your comment. My actual name is Minh, Quang is my middle name.

Quang Minh Bùi - 7 years, 10 months ago

We can try a simple programing solution using backtracking since the total number of possible paths is bounded by 2^24.

char seen[8][3];
int cnt=0;
int neigh[4][2]={{0,1},{0,-1},{1,0},{-1,0}};

bool valid(int x,int y)
{
  return (x>=0)&&(y>=0)&&(x<8)&&(y<3)&&(!seen[x][y]);
}

void work(int x,int y)
{
  if((x==0)&&(y==2))
  {
    cnt++;
    return;
  }
  seen[x][y]=1;
  for(int i=0;i<4;i++)
  {
    int xx=x+neigh[i][0],yy=y+neigh[i][1];
    if(valid(xx,yy))work(xx,yy);
  }
  seen[x][y]=0;
}

int main()
{
  work(0,0);
  printf("%d\n",cnt);
  return 0;
}

This gives the answer as 984.

CHEATER

Cody Johnson - 7 years, 10 months ago

Log in to reply

Excuse me?

Raziman Thottungal Valapu - 7 years, 10 months ago

Log in to reply

I think using the power of computer is not the aim of this section. Listing method is the last choice to solve combinatorial problems.

Quang Minh Bùi - 7 years, 10 months ago

Log in to reply

@Quang Minh Bùi Taking the eighth power of a matrix isn't particularly illuminating either. I wrote the code myself (and I think it is pretty neat for a backtracking problem), calling me a cheater is a bit too far don't you think?. Why can't people just live and let live?

Raziman Thottungal Valapu - 7 years, 10 months ago

Log in to reply

@Raziman Thottungal Valapu I have not called you a cheater. But I think if you consider the problem without using computer, you could find some better solutions, and your math skill may be improved. That's the aim of Brilliant in this Combinatorics section. (I also hope the Algorithms section will open soon)

P/S: I did the power manually (with the help of a calculator). In the last note, I've wrote that you only need to track the first row of matrix, the rest is not necessary. I know that there's another solution using recursion (without using computer). Hope they will post soon.

Quang Minh Bùi - 7 years, 10 months ago

Log in to reply

@Quang Minh Bùi I found a solution using recursion (but couldn't post a solution since I posted another). Basically, you have two recurrence relations for getting from the bottom-left to the top-left of a 3xn grid, and from the middle-left to the top-left of a 3xn grid. I can elaborate if you want.

Daniel Chiu - 7 years, 10 months ago
Boy Totitot
May 20, 2014

In general for 3 rows and n columns the number of self avoiding walks can be calculated via a recurrence relation. Let W ( n ) W(n) be the total number of self avoiding walks on 3 rows and n columns. Let us label the squares of G by ( x , y ) (x,y) where x = 1 , 2 , , n x = 1,2,\ldots, n and y = 1 , 2 , 3 y = 1,2,3 , the bottom left is (1,1) and the top left is (1,3).

W ( n + 1 ) W(n+1) is the number of walks that use n columns or less plus the number of walks that make use of the (n+1)th column. So W ( n + 1 ) = W ( n ) W(n+1) = W(n) + "Number of paths that use the (n+1)th column".

We will work out how many paths go through the (n+1)th column by extending those that go through the nth column. There are W ( n ) W ( n 1 ) W(n) - W(n-1) paths that go through the nth column: (i) ( n 1 , 1 ) ( n , 1 ) ( n , 2 ) ( n 1 , 2 ) (n-1,1)\to (n,1) \to (n,2) \to (n-1,2) (ii) ( n 1 , 2 ) ( n , 2 ) ( n , 3 ) ( n 1 , 3 ) (n-1,2) \to (n,2) \to (n,3) \to (n-1,3) (iii) ( n 1 , 1 ) ( n , 1 ) ( n , 2 ) ( n , 3 ) ( n 1 , 3 ) (n-1,1) \to (n,1) \to (n,2) \to (n,3) \to (n-1,3)

The paths can be extended to the (n+1)th column in the following ways (a) from (i): ( n 1 , 1 ) ( n , 1 ) ( n + 1 , 1 ) ( n + 1 , 2 ) ( n , 2 ) ( n 1 , 2 ) (n-1,1) \to (n,1) \to (n+1,1) \to (n+1,2) \to (n,2) \to (n-1,2) (b) from (i): ( n 1 , 1 ) ( n , 1 ) ( n + 1 , 1 ) ( n + 1 , 2 ) ( n + 1 , 3 ) ( n , 3 ) ( n , 2 ) ( n 1 , 2 ) (n-1,1) \to (n,1) \to (n+1,1) \to (n+1,2) \to (n+1,3) \to (n,3) \to (n,2) \to (n-1,2) (c) from (ii): ( n 1 , 2 ) ( n , 2 ) ( n + 1 , 2 ) ( n + 1 , 3 ) ( n , 3 ) ( n 1 , 3 ) (n-1,2) \to (n,2) \to (n+1,2) \to (n+1,3) \to (n,3) \to (n-1,3) (d) from (ii): ( n 1 , 2 ) ( n , 2 ) ( n , 1 ) ( n + 1 , 1 ) ( n + 1 , 2 ) ( n + 1 , 3 ) ( n , 3 ) ( n 1 , 3 ) (n-1,2)\to (n,2) \to (n,1) \to (n+1,1) \to (n+1,2) \to (n+1,3) \to (n,3) \to (n-1,3) (e) from (iii): ( n 1 , 1 ) ( n , 1 ) ( n + 1 , 1 ) ( n + 1 , 2 ) ( n + 1 , 3 ) ( n , 3 ) ( n 1 , 3 ) (n-1,1) \to (n,1) \to (n+1,1) \to (n+1,2) \to (n+1,3) \to (n,3) \to (n-1,3) (f) from (iii): ( n 1 , 1 ) ( n , 1 ) ( n + 1 , 1 ) ( n + 1 , 2 ) ( n , 2 ) ( n , 3 ) ( n 1 , 3 ) (n-1,1) \to (n,1) \to (n+1,1) \to (n+1,2) \to (n,2) \to (n,3) \to (n-1,3) (g) from (iii): ( n 1 , 1 ) ( n , 1 ) ( n , 2 ) ( n + 1 , 2 ) ( n + 1 , 3 ) ( n , 3 ) ( n 1 , 3 ) (n-1,1) \to (n,1) \to (n,2) \to (n+1,2) \to (n+1,3) \to (n,3) \to (n-1,3)

This means if there are p , q , r p, q, r paths of type (i), (ii), (iii) respectively we'll get 2 p + 2 q + 3 r 2p+2q+3r paths going through the (n+1)th column. Since there are W ( n ) W ( n 1 ) W(n) - W(n-1) paths going through the n-column we know p + q + r = W ( n ) W ( n 1 ) p+q+r = W(n) - W(n-1) We can see that r = W ( n 1 ) W ( n 2 ) r = W(n-1)-W(n-2) (the paths of type (iii) are simply the paths going through (n-1)th column extended similar to (b) (d) and (e)).

So W ( n + 1 ) = W ( n ) + 2 p + 2 q + 3 r = W ( n ) + 2 ( p + q + r ) + r W(n+1) = W(n) + 2p + 2q + 3r= W(n) + 2(p + q + r) + r . W ( n + 1 ) = W ( n ) + 2 ( W ( n ) W ( n 1 ) ) + W ( n 1 ) W ( n 2 ) W(n+1)= W(n) + 2(W(n) - W(n-1)) + W(n-1) - W(n-2) . W ( n + 1 ) = 3 W ( n ) W ( n 1 ) W ( n 2 ) W(n+1)=3W(n) - W(n-1) - W(n-2)

We can solve this recurrence relation using W(1) = 1, W(2) = 4, W(3) = 11. However, for this problem, only W(8) is needed. By substitution, W ( 8 ) = 984 W(8)=984 .

Rohit Sarathy
May 20, 2014

In general for 3 rows and n columns the number of self avoiding walks can be calculated via a recurrence relation. Let W(n) be the total number of self avoiding walks on 3 rows and n columns. Let us label the squares of G by (x,y) where x = 1, 2, ..., n, and y = 1, 2, 3, the bottom left is (1,1) and the top left is (1,3).

W(n+1) is the number of walks that use n columns or less plus the number of walks that make use of the n+1 column. So W(n+1) = W(n) + "Number of paths that use n+1 column".

We will work out how many paths go through the n+1 column by extending those that go through the n column. There are W(n) - W(n-1) paths that go through the n-column. They can go through the n column in the following ways (i) ... (n-1, 1) -> (n, 1) -> (n, 2) -> (n-1, 2) ...

(ii) ... (n-1, 2) -> (n, 2) -> (n, 3) -> (n-1, 3) ...

(iii) ... (n-1, 1) -> (n, 1) -> (n, 2) -> (n, 3) -> (n-1, 3) ...

The paths can be extended to the n+1 column in the following ways: (a) (i) turns to ... (n-1, 1) -> (n, 1) -> (n+1, 1) -> (n+1, 2) -> (n, 2) -> (n-1, 2) ...

(b) (i) turns to ... (n-1, 1) -> (n, 1) -> (n+1, 1) -> (n+1, 2) -> (n+1, 3) -> (n, 3) -> (n, 2) -> (n-1, 2) ...

(c) (ii) turns to ... (n-1, 2) -> (n, 2) -> (n+1, 2) -> (n+1, 3) -> (n, 3) -> (n-1, 3) ...

(d) (ii) turns to ... (n-1, 2) -> (n, 2) -> (n, 1) -> (n+1, 1) -> (n+1, 2) -> (n+1, 3) -> (n, 3) -> (n-1, 3) ...

(e) (iii) turns to ... (n-1, 1) -> (n, 1) -> (n+1, 1) -> (n+1, 2) -> (n+1, 3) -> (n, 3) -> (n-1, 3) ...

(f) (iii) turns to ... (n-1, 1) -> (n, 1) -> (n+1, 1) -> (n+1, 2) -> (n, 2) -> (n, 3) -> (n-1, 3) ...

(g) (iii) turns to ... (n-1, 1) -> (n, 1) -> (n, 2) -> (n+1, 2) -> (n+1, 3) -> (n, 3) -> (n-1, 3) ...

This means if there are p, q, r paths of type (i), (ii), (iii) respectively, we'll get 2p+2q+3r paths going through the n+1 column. Since there are W(n) - W(n-1) paths going through the n-column we know that

p + q + r = W ( n ) W ( n 1 ) . p + q + r = W(n) - W(n-1).

We can see that r = W ( n 1 ) W ( n 2 ) . r = W(n-1)-W(n-2).

( The paths of type (iii) are simply the paths going through n-1 column extended via extensions similar to (b), (d) and (e) ).

So W(n+1) = W(n) + "Number of paths that use n+1 column"

= W ( n ) + 2 p + 2 q + 3 r = W(n) + 2p + 2q + 3r

= W ( n ) + 2 ( p + q + r ) + r = W(n) + 2(p + q + r) + r

= W ( n ) + 2 ( W ( n ) W ( n 1 ) ) + W ( n 1 ) W ( n 2 ) = W(n) + 2(W(n) - W(n-1)) + W(n-1) - W(n-2)

= 3 W ( n ) W ( n 1 ) W ( n 2 ) = 3W(n) - W(n-1) - W(n-2)

We can solve this recurrence relation using W(1) = 1, W(2) = 4, W(3) = 11, to get 1 4 ( 2 + 2 ) ( 1 + 2 ) n + 1 4 ( 2 2 ) ( 1 2 ) n 1 \frac{1}{4}(2 + \sqrt{2})(1+ \sqrt{2})^n + \frac{1}{4}(2 - \sqrt{2})(1-\sqrt{2})^n - 1

Plugging in n = 8, since n is the number of columns, we get a grand total of 984 self-avoiding walks.

0 pending reports

×

Problem Loading...

Note Loading...

Set Loading...