
Found this puzzle inside an image. According to my thinking the total number of ways should be
2*comb(7,i) for i <- 1 to 7 where comb is defined as follows. Is my approach correct? I am concerned with the result that I get and not the function written below.
def comb(N,k):
if (k > N) or (N < 0) or (k < 0):
return 0L
N,k = map(long,(N,k))
top = N
val = 1L
while (top > (N-k)):
val *= top
top -= 1
n = 1L
while (n < k+1L):
val /= n
n += 1
return val
Don’t mind me asking too many questions in a short time period. I am just enthusiastic.
There are 7! ways to line up the children (7 choices for the first spot, 6 for the second, 5 for the third, etc.)
Each child can face inward or outward. That’s like an extra bit for each position.
So multiply by 2**7. (i.e. there are 2 choices for each spot).
Now for each ordering, if you rotate the circle, you get the “same” ordering. There are 7 rotations which all produce the same ordering, so divide by 7.
The answer is 2**7 * 7!/7 = 128* 6! = 92160.