Thursday, 20 April 2017

3D Model a Tower of Hanoi Puzzle with BlocksCAD

We've used BlocksCAD to code a Tower of Hanoi puzzle that can be printed and played with. This project brings together three of our favourite things: coding, 3D printing and logic puzzles. Oh and maths too, there's lots of neat maths.

This is good project for children and families who are just getting started with 3D printing. It's also good for developing logical thinking skills and using maths for something useful and interesting.

What is the Tower of Hanoi Puzzle?

The Tower of Hanoi is a well-known puzzle in which you have to move a set of discs from one tower to another by only placing smaller discs on top of larger ones. It's based on a legend that says the world will end when monks at a temple solve this puzzle for 64 discs and 3 towers. French mathematician Édouard Lucas designed the puzzle in 1883. There's more information on the origin and theory of the puzzle on Wikipedia

When I was a child my Dad made a metal version of this puzzle (he was a toolmaker) and I spent hours playing with it. 

The puzzle typically has three towers and three or more discs. We've used five discs for this version as that gives you enough to look for patterns in the solutions.

Using BlocksCAD

BlocksCAD allows you to create 3D models using drag and drop coding blocks. It's a great way for beginners to get started with 3D modelling. 

We use BlocksCAD with Microsoft 3D Builder which is great for fixing up any probems in the model and can send models directly to our Da Vinci Mini 3D printer

See also:

The Code

The Tower of Hanoi is a great 3D model for beginners to create as it can easily be made from geometric shapes.

If you're not in a hurry to get to the puzzle it's worth doing the maths the work out the sizes of the shapes.

The base is a cuboid, we tapered it to add a bit of interest. You could make it thicker if you have more patience than us! The towers are evenly spaced cylinders. 

Each disc can be made using a cylinder with another cylinder cut out of it using the difference operator. (Code is only shown for two of the discs, the other code is similar.)

We gave the towers a 4mm diameter and put a 5mm hole in the discs to allow for easy movement.

3D Printing

We printed the puzzle in two parts on a Da Vinci Mini 3D printer via Microsoft 3DBuilder. It's easy to split a model into multiple parts with a BlocksCAD as you can disable the blocks you don't want to include from the right-click menu.

We created one STL file for the base and towers and another for the discs. This meant we could print them in different colours.

We chose clear for the base and towers as it was already on the printer and then gold for the discs to fit with the legend.

The Puzzle

The first step is to solve the puzzle. Then to think about the smallest number of steps that it can be solved in. I got my kids to make a table showing the least number of moves for 1-5 discs. My 8 year old quickly worked out how to predict the next number in the sequence. We then talked about how to work out the number of moves given the number of discs. This lead to playing around with the google scientific calculator.

My 10 year old was interested in the number of moves it would take to solve the puzzle with 64 discs. This lead to some discussion around really big numbers and what the 'e' means in numbers on a scientific calculator.

The Algorithm

You could also look into the algorithm for solving the puzzle for different numbers of discs. After trying the puzzle a few times for different numbers of discs kids discover the algorithm for solving it in the fewest number of moves.

You can solve the puzzle with a 'recursive algorithm', an algorithm that calls itself with a smaller problem - in this case a smaller number of discs. Recursive solutions are often very elegant though they can be hard to understand at first. Recursion is one of the cool concepts in computer science.

For teens there's a good discussion of the Tower of Hanoi puzzle and its recursive solution in the Khan Academy Computer Science course.

What Next?

There's still more you can explore with this project. Can you design a 3D model for puzzles that use more discs? How does the 3D model need to change? Could you design a parameterized solution. You'll need to think about how far apart the towers need to be if you make the discs larger. 

More from Tech Age Kids:


Post a Comment