Can we view the hanoi tower algorithm as the following way?

  • Thread starter Thread starter pqrs008jeff
  • Start date Start date
  • Tags Tags
    Algorithm Tower
Click For Summary

Discussion Overview

The discussion revolves around the Tower of Hanoi algorithm, specifically exploring alternative methods of handling the algorithm by grouping plates into sets. Participants examine the implications of treating multiple plates as a single unit and the potential for optimizing the movement sequence in the context of using three stacks.

Discussion Character

  • Exploratory
  • Technical explanation
  • Debate/contested

Main Points Raised

  • One participant proposes a method to handle the Tower of Hanoi algorithm by treating three plates as one, suggesting that this could extend to larger sets of plates, such as nine or twenty-seven.
  • Another participant questions the necessity of using more than three stacks, emphasizing that the puzzle is designed to be solved with the minimum number of stacks.
  • A later reply introduces a new method called "HanoiTriples," which aims to generate the move sequence differently by using powers of three to represent the number of plates.
  • One participant expresses doubt about the feasibility of the proposed method, highlighting the challenge of adhering to the rule that larger plates cannot be placed on smaller ones when dealing with grouped plates.
  • Another participant insists that the problem is about the sequence of moves and suggests that viewing multiple plates as one could reveal a regular pattern in the movement sequence.
  • One participant asserts that there is a unique minimal-move solution to the problem and critiques the proposed method as potentially introducing unnecessary complications.

Areas of Agreement / Disagreement

Participants express differing views on the proposed method of grouping plates, with some supporting the exploration of this approach while others argue against it, emphasizing the established recursive algorithm's efficiency. The discussion remains unresolved regarding the effectiveness of the new method.

Contextual Notes

Some participants note that the proposed grouping method may complicate the movement rules, particularly regarding the placement of larger plates on smaller ones. There are also concerns about whether the new approach can yield a different or more efficient solution compared to the standard algorithm.

pqrs008jeff
Messages
3
Reaction score
0
the well known hanoi tower algorithm is as follow:
Code:
public static void hanoi(int n,int a,int b,int c)
  (
    if(n>0)
   (
    hanoi(n-1,a,c,b);
    move(a,b);
    hanoi(n-1,c,b,a);
   )
 )
my problem is : can we handle this algorithm in this method?
we can regard three places as one place which means that three places' case is the basic case, then we can solve the problem of nine places where three places are regarded as one place, and so on, we can solve the case of 27 places then to the case of places. if we realized that when we move three places, it means that we move 7 times which time we move one place, in this way we can solve the problem with remainder.
 
Last edited by a moderator:
Technology news on Phys.org
The algorithm that you're showing will work for any number of discs (as specified by "n").
When you say "place", I think you're referring to the number of stacks you are allowed to use. Since 3 stacks is sufficient, why do more the 3 stacks? The whole point of the puzzle is to manage with only the minimum.

Perhaps you are looking to make optimal use of more than three stacks? I can't quite catch what you're trying to do.
 
thank you for your help!
my problem is : can we handle this algorithm in this method?
we can regard three plates as one plate which means that three plates' case is the basic case, then we can solve the problem of nine plates where three plates are regarded as one plate, and so on, we can solve the case of 27 plates then to the case of plates. if we realized that when we move three plates, it means that we move 7 times which time we move one plate, in this way we can solve the problem with remainder.
here is the stacks,not the place. i make a mistake, sorry!
yes i want to search the optimal path of n stacks,such that:
a0*3^0+a1*3^1+a2*3^2+...+an*3^n
 
I see. So you're sticking with three stacks - but you're looking to generate the "move" sequence differently.
We'll call your new method HanoiTriples. It would take these arguments:

HanoiTriples(n3Power,a,b,c)
Where:
-> n3Power: indicates the number of plates as a power of 3. For example n3Power==0 indicates one plate, n3Power==1 indicates 3 plates.
-> a: Specifies the "move from" pile.
-> b: Specifies the "move to" pile.
-> c: Specifies the other pile.

I think you could make that work. Of course, if the number of discs was 2, 4, 5, or 6 instead of 1, 3, 9, or 27, then you would have to use Hanoi() instead of HanoiTriple().
 
I change my mind, it won't work.
Here's the algorithm we're talking about:
Code:
HanoiTriples(n3Power,a,b,c)
{
  if(n3Power<1) {
    Move(a,b);
  } else {
    HanoiTriples(n3Power-1,a,b,c);
    HanoiTriples(n3Power-1,a,c,b);
    HanoiTriples(n3Power-1,b,c,a);
    HanoiTriples(n3Power-1,a,b,c);
    HanoiTriples(n3Power-1,c,a,b);
    HanoiTriples(n3Power-1,c,b,a);
    HanoiTriples(n3Power-1,a,b,c);
  }
}
The problem is with the rule that big plates can't be put onto little plates - and when you're dealing with sets of three, sometime the bottom plate in the group of three will be bigger than the top plate is pile "c".
 
thank you for your advice!
but i don't think it is a problem like hanoi-triple!
this problem is about the sequence of the plates we move!even though we move one plate each step,but in general,there exists a special regular of the sequence we move.
if we view three plates as one ,the new sequence of the algorithm will appear in the former case that when we move one plate every step! eventually,if we view nine plates as one,the new sequence will appear in the case that when we move three plates each step!
 
I'm pretty sure I understand you correctly - and the code that I posted above does that.
I don't have the time right now, but later today I will post some JavaScript code which demonstrates what happens when you try to move a stack of 9 plates using your method.

But meanwhile, consider this: When you are moving 1 plate from stack "A" to stack "B", stack "C" is left alone. But when you move a group of 3 plates from "A" to "B", stack "C" is temporarily used to hold some of the plates. That temporary use is where the problem comes in.
 
So copy this into a file, give it an *.html file name, and open it up in your favorite browser.
It treats everything in a group of nine made up of groups of threes made up of single plates - but in the process it occasionally puts a big plate only a little plate.

If this isn't the algorithm you mean, feel free to modify the code to suit you purpose and let it run.

Code:
<html>
<head>
</head>
<body>
<table id="HanoiTable">
<tr><td align="center" width="150">&nbsp;</td><td align="center" width="150">&nbsp;</td><td align="center" width="150">&nbsp;</td></tr>
<tr><td align="center">&nbsp;</td><td align="center">&nbsp;</td><td align="center">&nbsp;</td></tr>
<tr><td align="center">&nbsp;</td><td align="center">&nbsp;</td><td align="center">&nbsp;</td></tr>
<tr><td align="center">&nbsp;</td><td align="center">&nbsp;</td><td align="center">&nbsp;</td></tr>
<tr><td align="center">&nbsp;</td><td align="center">&nbsp;</td><td align="center">&nbsp;</td></tr>
<tr><td align="center">&nbsp;</td><td align="center">&nbsp;</td><td align="center">&nbsp;</td></tr>
<tr><td align="center">&nbsp;</td><td align="center">&nbsp;</td><td align="center">&nbsp;</td></tr>
<tr><td align="center">&nbsp;</td><td align="center">&nbsp;</td><td align="center">&nbsp;</td></tr>
<tr><td align="center">&nbsp;</td><td align="center">&nbsp;</td><td align="center">&nbsp;</td></tr>
<tr><td bgcolor="black" colspan=3>&nbsp;</td></tr>

</table>

<script>

var HanoiTable = document.getElementById("HanoiTable");
var HanoiDrawIndex = 0;
var HanoiDrawCount = 0;
var HanoiDrawList = Array();

var HanoiRings=9;

var Towers=[
  [0,0,0,0,0,0,0,0,0,0],
  [0,0,0,0,0,0,0,0,0,0],
  [0,0,0,0,0,0,0,0,0,0]
];

function HanoiTriples(n3Power,a,b,c)
{
  if(n3Power<1) {
    HanoiMove(a,b);
  } else {
    HanoiTriples(n3Power-1,a,b,c);
    HanoiTriples(n3Power-1,a,c,b);
    HanoiTriples(n3Power-1,b,c,a);
    HanoiTriples(n3Power-1,a,b,c);
    HanoiTriples(n3Power-1,c,a,b);
    HanoiTriples(n3Power-1,c,b,a);
    HanoiTriples(n3Power-1,a,b,c);
  }
}

/*
function Hanoi(n,a,b,c)
{
  if(n>0) {
    Hanoi(n-1,a,c,b);
    HanoiMove(a,b);
    Hanoi(n-1,c,b,a);
  }
}
*/

function HanoiMove(a,b)
{
  nA = a-1;
  nB = b-1;

  var nRing=0;
  //
  // Remove top ring from tower a.
  nRing = 0;
  nASize = Towers[nA][0];
  if(nASize>0) {
    nRing = Towers[nA][nASize];
    Towers[nA][nASize] = 0;
    Towers[nA][0] = nASize-1;
    HanoiSetDraw(a,nASize,0,false);
  }
  //
  // Place it onto tower b.
  if(nRing>0) {
    nBSize = Towers[nB][0]+1;
    Towers[nB][0] = nBSize;
    Towers[nB][nBSize] = nRing;
    HanoiSetDraw(b,nBSize,nRing,true);
  }
}

function HanoiSetDraw(tower,level,ringsize,delay)
{
  var Move=Array();
  Move.tower=tower;
  Move.level=level;
  Move.ringsize=ringsize;
  Move.delay=delay;
  HanoiDrawList[HanoiDrawCount] = Move;
  HanoiDrawCount++;
}

function HanoiDraw()
{
  while(HanoiDrawIndex<HanoiDrawCount) {
    Move = HanoiDrawList[HanoiDrawIndex];
    HanoiDrawIndex++;
    HanoiCell = HanoiTable.rows[9-Move.level].cells[Move.tower-1];
    HanoiCell.innerHTML = "&nbsp;"+(Array(Move.ringsize+1).join("="));
    if(Move.delay) break;
  }
}Towers[0][0]=HanoiRings;
for(n=1;n<=HanoiRings;n++) {
  Towers[0][n] = HanoiRings-n+1;
  HanoiSetDraw(1,n,Towers[0][n],false);
}setInterval(HanoiDraw,250);

HanoiTriples(2,1,2,3);

</script>

</body>
</html>
 
There is a unique minimal-move solution to the problem and the standard recursive algorithm does that. In effect, it treats moving n-1 disks as a single set (a recursive call for moving n-1 disks). Your suggestion of treating 3 disks as a special case seems like a step backward that introduces unnecessary complications. The only way that it could get a different answer is if it makes unnecessary moves that it undoes later.
 

Similar threads

  • · Replies 25 ·
Replies
25
Views
5K
  • · Replies 5 ·
Replies
5
Views
3K
  • · Replies 11 ·
Replies
11
Views
5K
Replies
9
Views
3K
  • · Replies 5 ·
Replies
5
Views
2K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 12 ·
Replies
12
Views
2K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 4 ·
Replies
4
Views
2K
  • · Replies 4 ·
Replies
4
Views
2K