Riddler Express
I have a most peculiar menorah. Like most menorahs, it has nine total candles β a central candle, called the shamash, four to the left of the shamash and another four to the right. But unlike most menorahs, the eight candles on either side of the shamash are numbered. The two candles adjacent to the shamash are both the next two candles out from the shamash are the next pair are and the outermost pair are
The shamash is always lit. How many ways are there to light the remaining eight candles so that sums on either side of the menorah are βbalancedβ? (For example, one such way is to light candles and on one side and candles and on the other side. In this case, the sums on both sides are , so the menorah is balanced.)
Computational solution
The number of ways of lighting the candles satisfying the conditions is . The different ways of lighting the candles is given below:
(('l', 1), ('r', 1))
(('l', 2), ('r', 2))
(('l', 3), ('r', 3))
(('l', 4), ('r', 4))
(('l', 1), ('l', 2), ('r', 3))
(('l', 1), ('l', 3), ('r', 4))
(('l', 3), ('r', 1), ('r', 2))
(('l', 4), ('r', 1), ('r', 3))
(('l', 1), ('l', 2), ('r', 1), ('r', 2))
(('l', 1), ('l', 3), ('r', 1), ('r', 3))
(('l', 1), ('l', 4), ('r', 1), ('r', 4))
(('l', 1), ('l', 4), ('r', 2), ('r', 3))
(('l', 2), ('l', 3), ('r', 1), ('r', 4))
(('l', 2), ('l', 3), ('r', 2), ('r', 3))
(('l', 2), ('l', 4), ('r', 2), ('r', 4))
(('l', 3), ('l', 4), ('r', 3), ('r', 4))
(('l', 1), ('l', 2), ('l', 3), ('r', 2), ('r', 4))
(('l', 1), ('l', 2), ('l', 4), ('r', 3), ('r', 4))
(('l', 2), ('l', 4), ('r', 1), ('r', 2), ('r', 3))
(('l', 3), ('l', 4), ('r', 1), ('r', 2), ('r', 4))
(('l', 1), ('l', 2), ('l', 3), ('r', 1), ('r', 2), ('r', 3))
(('l', 1), ('l', 2), ('l', 4), ('r', 1), ('r', 2), ('r', 4))
(('l', 1), ('l', 3), ('l', 4), ('r', 1), ('r', 3), ('r', 4))
(('l', 2), ('l', 3), ('l', 4), ('r', 2), ('r', 3), ('r', 4))
(('l', 1), ('l', 2), ('l', 3), ('l', 4), ('r', 1), ('r', 2), ('r', 3), ('r', 4))
from itertools import product, combinations
def menorah_lighting(n=4):
side_sum = lambda comb, side: sum([i for s, i in comb if s == side])
candles = list(product(["l","r"], range(1, n+1)))
cnt, lightings = 0, []
for k in range(2, 2*n+1):
for comb in combinations(candles, k):
if side_sum(comb, "l") == side_sum(comb, "r"):
lightings.append(comb)
cnt += 1
return cnt, lightings
cnt, lightings = menorah_lighting()
print(cnt)
for l in lightings:
print(l)