Got it. But I think there is a problem with the representation, you are not representing the farmer. Remember, if the farmer is with the fox and the chicken its all good but if he goes away (even on an empty boat) that is a problem. So I think you need to add another dimension to your vector for the farmer.
That being said, there is a bigger problem here.
Lets say you four items x(1), ..., x(4). (Call this the n = 4 version). If left alone, x(a) eats x(a-1). (So in the original problem, the fox is x(3), the chicken is x(2) and the grain is x(1)).
Now, if the farmer takes any item across on the river, he loses right away. Why? Because either x(3) and x(4) are on the same side or x(3) and x(2) are on the same side or x(2) and x(1) are on the same side. No matter what, something gets eaten.
Another way to say this is that in the 4-cube, the point (0, 0, 0, 0) has no edges going out from it.
So, we need another parameter, c. c represents the capacity of his boat. If c = 2 this is easy. Take x(1) and x(3) across. Leave them there and come back. Then take x(2) and x(4) across. Done. That’s 3 crossings.
So with n = 4 and c = 1, no solution.
With n = 4 and c = 2, need 3 crossiings.
If n is even, and c = n/2, then you can always do it in 3 crossings.
1) Take x(1), x(3), ..., x(n-1).
2) Come back empty.
3)Take x(2), x(4), ..., x(n).
DONE
If n is even and c < n/2, you can’t do it. You will need to leave some pair x(a) and x(a+1) behind on your first crossing so you are dead.
If n is odd, you can do it with c = (n-1)/2. But it takes 7 crossings.
1) Take x(2), x(4), ..., x(n-1).
2) Come back empty.
3) Take x(1), x(3), ..., x(n-2)
4) Come back with x(2), x(4), ..., x(n-1).
5) Take x(n)
6) Come back empty.
7) Take x(2), x(4), ..., x(n-1).
DONE
If you work it through, you will see that each move is forced.
If n is odd and c > (n-1)/2, you can do it in 3 moves.
1) Take x(1), x(3), ..., x(n).
2) Come back empty.
3) Take x(2), x(4), ..., x(n-1).
DONE
Finally, of course, if c >= n, you can do it in one move.
To summarize
n even
> c < n/2—> impossible
> n/2 <= c < n—> 3 moves
> c >= n—> 1 move
n odd
> c < (n-1)/2—> impossible
> c = (n-1)/2—> 7 moves
> (n-1)/2 < c < n—> 3 moves
> c >= n—> 1 move