7

There are $n$ lights(numbered from $1$ to $n$), some of them are turned on. A turned off light can only be turned on if there is a light next to it turned on. In how many ways can you turn on all the lights?

For example: $$n=5$$ and the light number $3$ is on. $$0 0 1 0 0$$

answer is 6.

6 ways

43*12

32*14

42*13

41*23

31*24

21*34

The * means the initial turned on light. The numbers indicate the order in which the lights were turned on

I have tried recursively building the solution. But it is not time feasible.

A turned on light never goes off.

Somos
  • 37,457
  • 3
  • 35
  • 85
  • Can you explain a little more clearly the rules behind how lights can be transformed from one step to the next. Is it that if light $k$ is switched from its current state to the other state (so off to on, or on to off), then lights $k-1$ and $k+1$ are also switched from their currents states to the other state? Also, what does a "way" of turning on all the lights mean? Is it a sequence of light switches from the initial state to the all-on state? – Adam Lowrance Dec 07 '17 at 18:04
  • a turned on light never goes off – Moro Silverio Dec 07 '17 at 18:13
  • @AdamLowrance, I have edited the question for clearance – Moro Silverio Dec 07 '17 at 18:25
  • It is clear what you are asking in the question now. – Adam Lowrance Dec 07 '17 at 18:29
  • what is given as initial data ? a binary number ? – Abr001am Dec 07 '17 at 18:37
  • I think that if the input is binary or not, is not relevant @Abra – Moro Silverio Dec 07 '17 at 18:53
  • @MoroSilverio i think what is given as data is relevant. so this decides the way we tackle the problem, either by bitwise twiddling of a binary number, or a manipulation of other data. – Abr001am Dec 07 '17 at 19:03

2 Answers2

2

Let there be m sequences of consecutive lights which are turned off, and $a_i$ be number of lights of each sequence,$i\in\{1,...,m\}$.

If you watch only one sequence there is difference if the sequence is between two lightened lightballs or is at the end of row. If it is between then there is $2^{a_m-1}$ ways to choose order in which you will light them up, LRRLRR f.e. If it is on the end of row then there is only one way to turn them on going one by one.

Once you picked order of turning lights of each sequence you must decide order of the sequences you will turn a light from in each round. Number of it is $\frac{(\sum a_i)!}{\Pi (a_i!)}$

And total number is $\frac{(\sum a_i)!}{\Pi (a_i!)}\Pi (2^{a_j-1})$ where $j$ are indexes of the sequences that are in middle, so possibly without 1 or n.

In your example there are no sequences in the middle so you just have $\frac{(2+2)!}{ 2!2!}=6$

Here is an example which is more complicated: 0010001100001

So $a_1=2, a_2=3, a_3=4$ answer is $\frac{(2+3+4)!}{ 2!3!4!}2^{3-1}2^{4-1}$

  • I have no idea why you chose to divide by $2^{n-1}$, you know clearly that there is duplicates like LLLR = LLLL and LLRL=LLRR ? good solution though. – Abr001am Dec 07 '17 at 22:24
  • @Abra how do you mean I divide? I multiply it by $2^{m-1}$. And as you said LLLR=LLLL, thats why it goes power m-1 and not power m – Djura Marinkov Dec 07 '17 at 22:56
  • oh ok.this is better than my never ending formula. – Abr001am Dec 07 '17 at 22:57
0
  • I don't know what is given as data, but if the positions of turned on lamps is given first you should extract all contiguous extinguished lightbulbs.

Example:

000111010100110000

S= {{1,2,3},{7},{9},{11,12},{15,16,17,18}}

Next get the cardinals: |S|={3,1,1,2,4}

If you try to visualise the problem as a set of permutations, solution is just a multinomial distribution $\binom{n}{3,4,(1-1),(1-1),(2-1)}$

For a set of cardinals $|S|=\{x_0,x_1,x_2,x_3,x_4,...x_i\}$

Solution is $\binom{n}{x_0,\sum_j(x_1-j-1,j_1),\sum_j(x_2-j-2,j_2),...,x_i}$

$$=\sum_{j_1,j_2,...=0}\frac{n!}{x_0!(x_1-j_1-1)!j_1!(x_2-j_2-1)!j_2!...!x_i!}$$

Where $n$ is the number of extinct bulbs=$x_0+x_1+...x_n$.

Explanation:

For instance, a particular set of $x_0,x_1-j_1,j_1,x_2-j_2,j_2,...x_i$ and n extinct bulbls, permutations of these elements just notes the order of choosing either of these contiguous sub-lists, the act of choosing a sublist is visioned as clicking the edgemost switch of aligned ones that are all switched off, why $x_j-j-1$ ? because a set of complete $x_j$ encompasses one that is arranged with different list, so removing 1 from both opposite subsets as reserving a "nobody's land" of length=1 at the middle corrects the problem of duplicate choices.


Edit: After a bit of thinking i realised that a coincidence of choosing the no-cross line fixed between opposite subsets before $j$ or $x-j-1$ elements must be excluded, hence divided upon.

$S=\sum_{j_1,j_2,...=0}\frac{n!}{x_0!(x_1-j_1-1)!j_1!(j_1-1)(x_1-j_1-2)(x_2-j_2-1)!j_2!(j_2-1)(x_2-j_2-2)...!x_i!}$=$$\sum_{j_1,j_2,...=0}\frac{n!}{x_0!(x_1-j_1-1)!j_1!(x_2-j_2-1)!j_2!...!x_i!*(j_1-1)(x_1-j_1-2)(j_2-1)(x_2-j_2-2)...}$$

Abr001am
  • 766