The Tower of Hanoi Puzzle

*EDITED OPENSCAD CODE 12/18/17*

So this started when I was playing a batman themed computer game when I was a kid. On Batman’s desk you could play this game with 3 pegs and disks on them. You had to move the disks from the far left peg to the far right one and you couldn’t put a larger disk on a smaller disk and move only one disk at a time. I did some googling as an adult and I found out this puzzle was called The Towers of Hanoi.

I wanted to make one of these customize-able so like with the Geneva mechanism I used Openscad. I also have pretty bad luck with 3D printing shafts so I used wooden dowels. These are available from any hardware store.

The parameters should be pretty self explanatory so you probably don’t need me to go over them so I won’t. But below is my Openscad code or if you’d prefer, a Thingiverse link:


//Towers of Hanoi Puzzle

//By: Matt from 

//More info here
//https://en.wikipedia.org/wiki/Tower_of_Hanoi

//Number of disks
N= 6;

//Thickness of disks and half thickness of base
t= .375;

//Clearance amount (I use my nozzle diameter here)
tol = .4/25.4;

//Disk hole diameter
d= .375 + (2*tol);

//****** CHANGE FOR ROD DIAMETER AND AUTOMATICALLY ADD THE TOLERANCES ********
dbase = .375 + tol;

Eng=exp(ln(2)*N)-1;
echo(Eng);

DN= 2;
D0= 1;

Step=(DN-D0)/(N-1);

echo(Step);

Even=0;
Odd=DN + .25;

translate([0,DN/2,t/2]){
for(i=[2:N-1])
    if(i%2==0){
        translate([Even,(Odd) + ((i-2)*(Odd/2)),0]){
            difference(){
                cylinder(t,(D0+(Step*(i-1)))/2,(D0+(Step*(i-1)))/2,center = true,$fn=100);
                cylinder(2*t,d/2,d/2,center = true,$fn=100);
    }}}
    else{
        translate([Odd,(Odd) + (((i-2)-1)*(Odd/2)),0]){
            difference(){
                cylinder(t,(D0+(Step*(i-1)))/2,(D0+(Step*(i-1)))/2,center = true,$fn=100);
                cylinder(2*t,d/2,d/2,center = true,$fn=100);
    }}}

translate([Odd,0,0]){
difference(){
    cylinder(t,D0/2,D0/2,center = true,$fn=100);
    cylinder(2*t,d/2,d/2,center = true,$fn=100);
    }}

 
difference(){
    cylinder(t,DN/2,DN/2,center = true,$fn=100);
    cylinder(2*t,d/2,d/2,center = true,$fn=100);
    }}

translate([-Odd*1.25,((3*DN)+1)/2,t]){
    difference(){
        cube([DN+.5,(3*DN)+1,2*t],center=true);
rotate([0,0,90]){
    translate([0,-(DN/2)+.25,t-.0625]){
        linear_extrude(.125,center=true){
text(str(Eng), font = "Liberation Sans", size = .75,halign="center",valign="center");
}}}
cylinder(2*t,dbase/2,dbase/2,center=true,$fn=1000);
translate([0,DN+.25,0]){
    cylinder(2*t,dbase/2,dbase/2,center=true,$fn=1000);
}
translate([0,-(DN+.25),0]){
    cylinder(2*t,dbase/2,dbase/2,center=true,$fn=1000);
}
}
}

Something cool (I think) that I incorporated into the model was the text on the base that displays the number of moves it takes to solve the puzzle.

My 6 disk puzzle

As you can see I printed out a 6 disk version which means it takes 63 moves to solve. Below I have a GIF of me solving my puzzle a fair bit faster than I actually solved it.

This is a pretty cool desk toy but you sort of get used to the algorithm to solve it… so just print a massive one that takes too long to solve and you’ll never get bored!

Leave a Reply

Your email address will not be published. Required fields are marked *