| |
|
|
p.specht
| knew your, that the 'Türme of Hanoi' really from france stammen?
Window Title upper$("Türme of Hanoi, rekursiv")
Window Style 24:Window 0,0-%maxx,240:randomize:font 2
print "\n Info: are n Scheiben on 3 post pretended, so need one at least 2^n-1 steps."
print "\n The problem is in this Aufbereitung popular, around the Difference between of/ one "
print " rekursiven statement [(x(1)=1 and x(n+1)=2*x(n)+1] and expliziter statement [x(n)=2^n-1]"
print " of/ one follow To demonstrating."
waitinput 5000
Print "\n to story the approach to the problem:\n"
Print " The french Mathematiker Édouard Lucas (1842-1891) erfand this game "
Print "And sold it as toy erstmals in the years 1883. moreover thought itself Lucas "
print " a story from: Hindupriester should on order their Gottes Brahma "
print " 64 Scheiben umlegen. moreover required tappt im dunkeln theoretical at least 2^64-1 = "
print " 1.8*10 ^19 moves. becomes in eachone second a slice umgelegt, so lasts the "
print " 580 Billion years. the universe is presently 13,48 Mrd years old and becomes "
print "The sped Expansionstod (Atome rend kausal) presumably in ca."
print " 48 Mrd years experience. take we means Perhaps something less Scheiben...\n"
waitinput 5000
print " \n an nonrekursive Algorithmus-Variante shining *for Humans* überraschend simply:\n"
print " as long as the Turm not entire moving watts: "
print " - move The smallest slice a Space modulo 3 to right *)"
print " - lead The only possible movement of/ one not-kleinsten slice from.\n____\n"
print " *): Scheibenzahl ungerade? supplant 'right' through 'left' \n"
print "\n here follows but a rekursive Variante, circa so XProfan auszutesten."
declare n&,m&
print "\n\n\n desired Scheibenzahl ?:",:input n&
Window Title " TASTE Q for SCHNELL-LAUF DRÜCKEN "
cls
declare h&[3,n&],v&[3],z&
whileloop n& : h&[1,&Loop]=n&+1-&Loop : endwhile :
v&[1]=n&
m&=n&
show 1,2
waitinput 1000
hanoi(n&,1,2,3)
beep
waitinput
end
proc hanoi :parameters n&,von&,nach&,ueber&
if n&=1
move(von&,nach&)
elseif n&>1
hanoi(n&-1,von&,ueber&,nach&)
move(von&,nach&)
hanoi(n&-1,ueber&,nach&,von&)
endif
endproc
proc move :parameters von&,nach&
v&[nach&]=v&[nach&]+1
h&[nach&,v&[nach&]]=h&[von&,v&[von&]]
h&[von&,v&[von&]]=0:v&[von&]=v&[von&]-1
show von&,nach&
case %key<>113:waitinput 1000
endproc
proc Show :parameters von&,nach&
locate 1,1
inc z&
print " ";z&;":",von&;">";nach&;" "
print "------------------------"
case %key<>113:waitinput 1000
declare v&,w&
whileloop 1,3:v&=&Loop
print " ";v&;": ",
whileloop 1,m&
w&=&Loop
if h&[v&,w&]>0:print h&[v&,w&],
else :print ".",
endif
endwhile
print
endwhile
print "------------------------"
endproc
|
|
|
| XProfan 11Computer: Gerät, daß es in Mikrosekunden erlaubt, 50.000 Fehler zu machen, zB 'daß' statt 'das'... | 05/16/21 ▲ |
|
|
|