Numerit[WIN32][1700][1703]z++ qffffff)@j@fffffvq@?@ffffff9@?@ffffff9@ffffff)@ffffff)@        Times New RomanArialSymbol Courier New???߿ G +V@*ηM@ yx1yx2yx3yr.1xr.1yr.2xr.2yr.3xr.3yr.4xr.4yr.5xr.5yr.6xr.6ybasexbase@@@@@@@@@@@@@@@@@ @@@@ @@>@>@>@>@>@ @@   @@==>>??0820.010.01-404050.010.01G QM@ C@ yx1yx2yx3yr.1xr.1yr.2xr.2yr.3xr.3yr.4xr.4yr.5xr.5yr.6xr.6ybasexbase@@@@@@@@@@@@@@ @@@@ @@>@>@>@>@>@ @@   @@==>>??0820.010.01-404050.010.01333333?@8333333?@333333?@8@333333@333333@ffffff @ffffff @ffffff@ffffff@??<3>2?0@.333333@333333@ffffff @ffffff @ffffff@ffffff@??<3>2?0@.333333@333333@ffffff @ffffff @ffffff@ffffff@??<3>2?0@.333333@333333@ffffff @ffffff @ffffff@ffffff@??<3>2?0@.333333@333333@ffffff @ffffff @ffffff@ffffff@??<3>2?0@.333333@333333@ffffff @ffffff @ffffff@ffffff@??<3>2?0@.333333?BB@G QM@ C@ yx1yx2yx3yr.1xr.1yr.2xr.2yr.3xr.3yr.4xr.4yr.5xr.5yr.6xr.6ybasexbase@@@@@@@@@@@@@@ @@@@ @@>@>@>@>@>@ @@   @@==>>??0820.010.01-404050.010.01333333?@8333333?@333333?@8@333333@333333@ffffff @ffffff @ffffff@ffffff@??3@<@2@>@0@?@.@@@333333@333333@ffffff @ffffff @ffffff@ffffff@??3@<@2@>@0@?@.@@@333333@333333@ffffff @ffffff @ffffff@ffffff@??3@<@2@>@0@?@.@@@333333@333333@ffffff @ffffff @ffffff@ffffff@??3@<@2@>@0@?@.@@@333333@333333@ffffff @ffffff @ffffff@ffffff@??3@<@2@>@0@?@.@@@333333@333333@ffffff @ffffff @ffffff@ffffff@??3@<@2@>@0@?@.@@@333333?BB@ׇׇׇpׇׇׇpׇׇׇpׇׇׇpׇׇׇpׇׇׇpׇׇׇ ׇׇׇ0Towers of Hanoiׇׇׇ The Towers of Hanoi is a well known puzzle whose purpose is to move #n rings of descending diameters from post #S (source) to post #D (destination) using an intermediate post #I, while obeying the following rules:9ׇׇׇ 1. Move only one ring at a time from one post to another.,ׇׇׇ 2. Never put a ring on top of a smaller one.ׇׇׇ )ׇׇׇffBB ^!Starting position "End position(ׇׇׇffBffBB ? ! / O #4=> / P " KׇׇׇRAffBpZB{BB\C m 1!#S T #I U #D B"#S T #I U #Dׇׇׇ ׇׇׇ It's quite amazing that a very simple recursive algorithm solves this problem, for any number of rings. The solution is very elegant and looks like magic. The recursive mechanism takes care of everything: you just tell it to move the top #n-1 rings from #S to #I using #D as the intermediate post, then move the last (and largest) ring from #S to #D, and then move the #n-1 rings from #I to #D using #S as the intermediate post. And that's all! ,ׇׇׇ Now press the Play button (or F9) and watch.ׇׇׇ ׇׇׇ  ׇׇׇ :ׇׇׇQB3B F9 = Play m *!F5 = Stop \ F6 = Pause q8ffffff)@j@fffffvq@?@ffffff9@?@ffffff9@ffffff)@ffffff)@        Times New RomanArialSymbol Courier New >` This sample program demonstrates a recursive algorithm is byB` showing a solution to the well known game - the Towers of Hanoi.%` -> Move to the bottom of the Report"` to see the graph viewer and then` run the program.6` The function 'hanoi' is the recursive algorithm that6` actually solves the problem. All the other functions9` are used to define the coordinates of the rings at each:` stage so that the solution can be displayed graphically.9` The main code at the bottom calls 'hanoi' repeatedly so1` that the solution is displayed again and again.7` Note: to change the speed of the animation modify the` parameter delay below. ` parametersdelay = 0.01 ` sec(n = 4 ` number of rings (default value)=`------------------------------------------------------------+` The recursive function (Hanoi algorithm).4` Note how hanoi calls itself to solve the same task` with one ring less.:function hanoi(n,s,d,i) ` move n rings from s to d using i if n > 0:hanoi(n-1,s,i,d) ` move n-1 rings from s to i using d-move(n,s,d) ` move ring n from s to d=hanoi(n-1,i,d,s) ` move the n-1 rings from i to d using s=`------------------------------------------------------------;` define xr,yr: coordinates of ring i on post p at height hfunc putring(i,p,h)w = 6-%n+i ` width%xr[i,*] = -w,w%xr[i,*] *= 1.5,%xr[i,*] += (p-2)*%xmax ` use global 'xmax'%yr[i,*] = h+1.3=`------------------------------------------------------------` move ring 'i' up post 'p' func up(i,p)*h = %ph[p]+%del ` initial ring heightwhile h < %ymaxputring(i,p,h) refresh ` update viewer h += %del wait %delay&putring(i,p,%ymax) ` final ring height"refresh ` update viewer4%ph[p] -= 1 ` new post height: decrease by 1=`------------------------------------------------------------` move ring 'i' down post 'p'func down(i,p)+h = %ymax ` initial ring heightwhile h > %ph[p]putring(i,p,h)!refresh ` update viewer h -= %del wait %delay'putring(i,p,%ph[p]) ` final ring height#refresh ` update viewer5%ph[p] += 1 ` new post height: increase by 1=`------------------------------------------------------------&` move ring 'i' horizontally to post qfunc slide(i,q)w = 6-%n+i ` widthxq = -1.5*w+(q-2)*%xmax xp = %xr[i,1] n = abs(round((xq-xp)/(%del*7)))dx = (xq-xp)/nfor j = 1 to n%xr[i,*] += dxrefresh wait %delay=`------------------------------------------------------------` move from post p to post qfunc move(i,p,q)up(i,p) ` take out slide(i,q)down(i,q) ` put down=`------------------------------------------------------------` put n rings on post pfunc init(n,p) clear %phfor j = n downto 1 down(j,p)=`------------------------------------------------------------` Main code starts here` initializationsE` ask for the number of rings (if not in the range 1..6: keep asking)Frepeat input "Enter number of rings (1..6)" n until n >= 1 and n <= 6s = 1 ` source: from post 1d = 3 ` destination: to post 3$i = 2 ` intermediate: trough post 2-del = 0.25 ` ring vertical movement pitch;xmax = 24 ` distance between center post to side posts%ymin = 0.3 ` lowest ring position&ymax = 6 ` highest ring position#x1 = -xmax ` location of post 1#x2 = 0 ` location of post 2#x3 = xmax ` location of post 3"y = ymin,ymax ` post height range/xbase = -1.5*xmax,1.5*xmax ` base width range1ybase = ymin ` y position of baseEph[3]=0 ` array: current heights of posts 1 to 31xr[n,2]=0 ` ring x-coordinates1yr[n,2]=0 ` ring y-coordinates=`------------------------------------------------------------ ` main loop:#` call hanoi indefinitely in a loop+` until interrupted by user (Pause or Stop)loop)init(n,s) ` put n rings on post swait 1 ` stand by2hanoi(n,s,d,i) ` move rings from s to d through ibeepwait 3 ` restd:\num\num1.5\run\ delaynxr xmaxyr phdelymaxsdiyminx1 x2 x3 y xbase ybase  l  j p  Z  [`7l m  n  p r s  t v G w  x y 5z G B  B5{ | 4 }  4 ~  4   <?     <?  6 kV hanoihanoinsdi !  X7  A   <?   <?  A   <?> movemoveipq WX  <?Y  <?Z  <?[> putringputringiphw 8"# / 0A @$ 4 G 5/0% 4 /U0& 4  A/ 0B/S0' 4  @/0(> upupiph 8,- 4/ 0@. / 0Y7/   <?01/ 0N2/ 0 63  / 0<?45 4 /T06> % downdowniph 8:;/ 0<  4/0X7=   <?>?/ 0O@/ 0 6A   4/0<?BC 4 /S0D># slide slideiqwxqxpndxj PHI / 0A @J G B  A/ 0B@K  4/0L  A/ 0 BCM  A CN   X8O 4 /S0PQ/ 0 N6S>8KN initinitnpj _`/ 0a   Y8  <? O6b>  0.01{Gz?4@01?6@1.5?2@1.3?7@Enter number of rings (1..6)3@0.25?248@0.3333333?