The faces of $n$ unit cubes have been painted either black or white at random. The faces of $n$ unit cubes have been painted either black or white at random. What is the probability that these cubes can be lined up to make a 'white train' , an $1 \times 1 \times n$ box which only white faces are visible ? I have found that for the middle cubes will need $6C6+6C5+6C4+6C3$ possible arrangements and there are a total of $2^{64}$ TOTAL arrangements .
What is tough is how to find the 'ends' or how many arrangements will result in the ends of this 'train' being white too. I computed $24$ ways since for each face there are $4 \times 6$ ways.
 A: Note: The following calculation is for a $1\times n$ train with all 6 faces white.

Method 1: Elementary Counting
Firstly assume each cube can have either:


*

*No black faces ($1$ colouring)

*$1$ black face ($6$ colourings)

*$2$ opposite black faces ($3$ colourings)


then, as there are $n$ cubes there are $(1+6+3)^n=10^n$ colourings of types 1, 2 and 3.
However, we have over counted since there are, amongst our $10^n$ colourings, $3^n$ colourings that have exactly $n$ cubes with $2$ opposite black faces, and $\binom{n}{1}\cdot (6+1)\cdot 3^{n-1}$ colourings that have exactly $n-1$ cubes with $2$ opposite black faces. 
Subtract these to give
$$10^n-3^n-7n\cdot 3^{n-1}$$
colourings which allow us to form a white train. 
Since each cube has $6$ faces, each cube has $2^6$ total possible colourings. Then, as there are $n$ cubes, there are $2^{6n}$ total colourings of all the $n$ cubes, so the probability of being able to form a white train is:
$$\frac{10^n-3^n-7n\cdot 3^{n-1}}{2^{6n}}\tag{Answer}$$
Method 2: Using Exponential Generating Functions
I orginally formulated the problem in terms of exponential generating functions (egfs). For completeness here is what I did:
Formulate an egf for cube colourings with $0$ ($z_0$) or $1$ ($z_1$) black face. There must be at least $2$ of these so it's egf is:
$$\frac{1}{2!}(z_0+6z_1)^2+\frac{1}{3!}(z_0+6z_1)^3+\frac{1}{4!}(z_0+6z_1)^4+\cdots=e^{z_0+6z_1}-(z_0+6z_1)-1$$
Next formulate an egf for cube colourings with $2$ opposite black faces ($z_2$). There can be any number of these so we have it's egf:
$$1+\frac{1}{1!}(3z_2)+\frac{1}{2!}(3z_2)^2+\frac{1}{3!}(3z_2)^3+\cdots=e^{3z_2}$$
Multiply these together to give our egf that enumerates valid colourings 
$$(e^{z_0+6z_1}-(z_0+6z_1)-1)e^{3z_2}$$
where the coefficient of $z_0^{k_0}z_1^{k_1}z_2^{k_2}$ tells us the number of valid colourings with $k_0$ all white cubes, $k_1$ cubes with $1$ black face and $k_2$ cubes with $2$ opposite black faces.
We are only interested in enumerating according to the total number of cubes so we need not distinguish $z_0$, $z_1$ and $z_2$: put $z_0=z_1=z_2=z$ then the desired egf is now:
$$(e^{7z}-7z-1)e^{3z}=e^{10z}-7ze^{3z}-e^{3z}$$
and taking the $z^n/n!$ coefficient gives us the desired count for valid colourings:
$$[z^n/n!](e^{10z}-7ze^{3z}-e^{3z})=10^n-7n\cdot 3^{n-1}-3^n$$
as before. Which then leads to the same probability.
A: Note: The following calculation is for a $1\times n$ train resting on a surface with $5$ visible sides white.

Here I present an elementary counting method only
Assume each cube has either:


*

*All white faces ($1$ colouring)

*$1$ black face ($6$ colourings)

*$2$ black faces ($\binom{6}{2}=15$ colorings)

*$3$ black faces not all adjacent to a single corner ($\binom{6}{3}-8=12$ colorings)


There are therfore $(1+6+15+12)^n=34^n$ colourings of type 1,2,3 and 4.
We have over counted, though, because amongst these $34^n$ colourings there are $(12+3)^n=15^n$ where all $n$ cubes have $3$ black faces (described by 4 above) or $2$ opposite black faces ($3$ of the $15$ described by 2 above). 
Also, amongst the $34^n$ there are $\binom{n}{1}\cdot (12+6+1)\cdot 15^{n-1}$ colourings where exactly $n-1$ cubes have $3$ black faces (described by 4 above) or $2$ opposite black faces ($3$ of the $15$ described by 2 above) and only $1$ cube has either $2$ adjacent black faces ($12$ of the $15$ described by 2 above) or $1$ black face (described by 2 above) or all white faces (as described by 1 above).
Subtracting these two cases from $34^n$ gives valid colourings:
$$34^n-15^n-19n\cdot 15^{n-1}$$
and since there are $2^{6n}$ total colourings of $n$ cubes the desired probability is:
$$\frac{34^n-15^n-19n\cdot 15^{n-1}}{2^{6n}}\tag{Answer}$$
I will leave the generating function approach but it yields, in this case, an egf for valid colourings: $e^{34z}-19ze^{15z}-e^{15z}$.
A: this might be 1 solution. two end cubes have to have 
both two opposite faces white and two faces that share  an edge which there are 6 and 12 ways to paint these,on one cube so p(n)= [((6c6+6c5 6c4+6c3)n)/64+(2)(6)(12)/2^6n] . the train needs 2 end cubes as well .( starting with one middle cube after we have got the two end cubes is the first part)
