Yesterday evening, the 21st Web Montag Cologne took place. The list of participants had already been growing constantly during the last days before the event, but when @fbz, @scompt and me arrived at ~19:30, I was surprised anyway how many people where already there and engaged in lively discussions. Starting from 8 o’clock, three talks were given.

Jörn Zaefferer (@bassistance) presented the newly released jQuery 1.4. It offers new features and also an improved performance. If you use jQuery, it might be worth upgrading, despite some backwards-imcompatibilities. A lot of work has also been done on the website and the documentation.

Christoph Beckmann (@cbek) talked about his experiences surviving a traffic peak caused by TV appearance with the help of Amazon Web Services. The solution involved migrating the Loo2Go server to a big EC2 instance and using several caching servers. While the costs were marginal, the approach seems very labour intense to me.

For Christmas, I got the ThinkFun 36 Cube. It is consists of 36 towers in 6 colors and 6 different sizes and a base plate with 6 by 6 slots to plug in the towers. These slots are of different heights. The goal is to place one towers of every color in each row and column. And the towers must fit to form a level cube.

After some tries, I came to the conclusion that this puzzle is the work of the devil and that I should not waste more brain cycles on solving it. So I wrote a little python script to solve the puzzle for me.

#!/usr/bin/python
COLORS =dict(zip((1 << i for i inrange(6)),('P','Y','O','B','R','G')))
COLORS[False]='X'
used_towers =[0for i inrange(6)]
cube =((1,3,4,5,2,0),(2,5,0,4,1,3),(0,1,3,2,5,4),(5,4,1,3,0,2),(4,2,5,0,3,1),(3,0,2,1,4,5))
solution =[[Falsefor x inrange(6)]for x inrange(6)]
used =tuple(set()for i inrange(6))def test_color(pos, solution, used_towers, color, size):
#check if tower of this size and color has already been usedif color & used_towers[size]:
returnFalse#check if tower has already been used in row or column:for i inrange(6):
if color == solution[pos/6][i]: returnFalseif color == solution[i][pos%6]: returnFalsereturnTruedef print_solution(solution):
for i inrange(6):
printzip((COLORS[c]for c in solution[i]),(6 - s for s in cube[i]))def solve(pos, solution, used_towers, best):
if pos ==36: return best, solution
size = cube[pos/6][pos%6]for i inrange(6):
color =1 << i
if test_color(pos, solution, used_towers, color, size):
used_towers[size]= used_towers[size] | color
solution[pos/6][pos%6]= color
if pos > best:
print"#######", pos + 1,"towers placed"
print_solution(solution)
best = pos
best, solution = solve(pos+1, solution, used_towers, best)if best >=35:
return best, solution
solution[pos/6][pos%6]=False
used_towers[size]= used_towers[size] ^ color
return best, solution
solve(0, solution, used_towers,0)

#!/usr/bin/python
COLORS = dict(zip((1 << i for i in range(6)), ('P','Y','O','B','R','G')))
COLORS[False] = 'X'
used_towers = [0 for i in range(6)]
cube = ((1,3,4,5,2,0),
(2,5,0,4,1,3),
(0,1,3,2,5,4),
(5,4,1,3,0,2),
(4,2,5,0,3,1),
(3,0,2,1,4,5))
solution = [[False for x in range(6)] for x in range(6)]
used = tuple(set() for i in range(6))
def test_color(pos, solution, used_towers, color, size):
#check if tower of this size and color has already been used
if color & used_towers[size]:
return False
#check if tower has already been used in row or column:
for i in range(6):
if color == solution[pos/6][i]: return False
if color == solution[i][pos%6]: return False
return True
def print_solution(solution):
for i in range(6):
print zip((COLORS[c] for c in solution[i]), (6 - s for s in cube[i]))
def solve(pos, solution, used_towers, best):
if pos == 36: return best, solution
size = cube[pos/6][pos%6]
for i in range(6):
color = 1 << i
if test_color(pos, solution, used_towers, color, size):
used_towers[size] = used_towers[size] | color
solution[pos/6][pos%6] = color
if pos > best:
print "#######", pos + 1, "towers placed"
print_solution(solution)
best = pos
best, solution = solve(pos+1, solution, used_towers, best)
if best >= 35:
return best, solution
solution[pos/6][pos%6] = False
used_towers[size] = used_towers[size] ^ color
return best, solution
solve(0, solution, used_towers, 0)

My program quickly came up with a correct placement for 34 towers – but it failed to find the complete solution.

Legend:
P = Purple, Y = Yellow, O = Orange, B = Blue, R = Red, G = Green, X = Empty
The number is the size of the tower.
As you can see, I didn’t waste much time on making the output pretty 🙂

So close and yet so far

After spending lots of time verifying that my program was working correctly, I became impatient and googled for help. I found an answer, but it revealed to much, taking all the fun.

Therefore, I split my solution into multiple hints. If you are stuck, reveal just one of them at a time and try to figure it out by yourself. It is way more rewarding!

Hint #1 (show): Your assumptions are probably wrong.
Now go back and try to solve it. I’m waiting here.

Hint #2 (show): The assumption that all towers of the same size only differ in color is wrong.

Hint #3 (show): There are two towers which do fit on slots where the other towers of the same size do not fit.

Hint #4 (show): The two special towers are the yellow one of heigh 5 and the orange one of height 6.

Hint #5 (show): The yellow tower of height 5 has to go to position (1,2) and the orange tower of height 6 to (3,2) in my coordinate system.

Even if you uncovered all hints, the puzzle is still far from solved. You can still tinker with it forever.

Spoiler alert: Don’t uncover the solution, unless your are really desperate!

After I had found the two culprits, I adjusted my program by changing the array and inserting two special conditions. Within seconds I had a complete solution of the 36 Cube:

#!/usr/bin/python
COLORS =dict(zip((1 << i for i inrange(6)),('P','Y','O','B','R','G')))
COLORS[False]='X'
used_towers =[0for i inrange(6)]# definition with (1,2) and (3,2) switched
cube =((1,3,4,5,2,0),(2,5,1,4,1,3),(0,1,3,2,5,4),(5,4,0,3,0,2),(4,2,5,0,3,1),(3,0,2,1,4,5))
solution =[[Falsefor x inrange(6)]for x inrange(6)]
used =tuple(set()for i inrange(6))def test_color(pos, solution, used_towers, color, size):
#check if tower of this size and color has already been usedif color & used_towers[size]:
returnFalse#check if tower has already been used in row or column:for i inrange(6):
if color == solution[pos/6][i]: returnFalseif color == solution[i][pos%6]: returnFalse# special conditions for the two special towersif(pos/6, pos%6)==(1,2)and color !=2: returnFalseif(pos/6, pos%6)==(3,2)and color !=4: returnFalsereturnTruedef print_solution(solution):
for i inrange(6):
printzip((COLORS[c]for c in solution[i]),(6 - s for s in cube[i]))def solve(pos, solution, used_towers, best):
if pos ==36: return best, solution
size = cube[pos/6][pos%6]for i inrange(6):
color =1 << i
if test_color(pos, solution, used_towers, color, size):
used_towers[size]= used_towers[size] | color
solution[pos/6][pos%6]= color
if pos > best:
print"#######", pos + 1,"towers placed"
print_solution(solution)
best = pos
best, solution = solve(pos+1, solution, used_towers, best)if best >=35:
return best, solution
solution[pos/6][pos%6]=False
used_towers[size]= used_towers[size] ^ color
return best, solution
solve(0, solution, used_towers,0)

#!/usr/bin/python
COLORS = dict(zip((1 << i for i in range(6)), ('P','Y','O','B','R','G')))
COLORS[False] = 'X'
used_towers = [0 for i in range(6)]
# definition with (1,2) and (3,2) switched
cube = ((1,3,4,5,2,0),
(2,5,1,4,1,3),
(0,1,3,2,5,4),
(5,4,0,3,0,2),
(4,2,5,0,3,1),
(3,0,2,1,4,5))
solution = [[False for x in range(6)] for x in range(6)]
used = tuple(set() for i in range(6))
def test_color(pos, solution, used_towers, color, size):
#check if tower of this size and color has already been used
if color & used_towers[size]:
return False
#check if tower has already been used in row or column:
for i in range(6):
if color == solution[pos/6][i]: return False
if color == solution[i][pos%6]: return False
# special conditions for the two special towers
if (pos/6, pos%6) == (1,2) and color != 2: return False
if (pos/6, pos%6) == (3,2) and color != 4: return False
return True
def print_solution(solution):
for i in range(6):
print zip((COLORS[c] for c in solution[i]), (6 - s for s in cube[i]))
def solve(pos, solution, used_towers, best):
if pos == 36: return best, solution
size = cube[pos/6][pos%6]
for i in range(6):
color = 1 << i
if test_color(pos, solution, used_towers, color, size):
used_towers[size] = used_towers[size] | color
solution[pos/6][pos%6] = color
if pos > best:
print "#######", pos + 1, "towers placed"
print_solution(solution)
best = pos
best, solution = solve(pos+1, solution, used_towers, best)
if best >= 35:
return best, solution
solution[pos/6][pos%6] = False
used_towers[size] = used_towers[size] ^ color
return best, solution
solve(0, solution, used_towers, 0)