English
Experimente

four-post-Variante of "Türme of Hanoi" (rekursiv)

 

p.specht

Note: on the Internetseiten of 'Stack Overflow' is even a Variante with discretionary many post (Engl.:'Pegs') to find, though in the sooner ungewöhnlichen Language 'F#'. tappt im dunkeln using the Vernehmen to whom iterativen 'Frame-Stewart Algorithmus'. here allderdings the Standardalgorithmus lt. Textbook. Rekursion is though no large strength of XProfan...
Window Title upper$("Türme of Hanoi with 4 post, rekursiv")
Window Style 24:Window 0,0-%maxx,240:randomize:font 2
print "\n here a rekursive Variante with 4 Pfosten"
declare n&,m&
print "\n\n\n desired Scheibenzahl ?:",:input n&
Window Title " TASTE Q for SCHNELL-LAUF DRÜCKEN "
cls
declare h&[4,n&],v&[4],z&

whileloop n& : h&[1,&Loop]=n&+1-&Loop : endwhile :

    v&[1]=n&
    m&=n&
    show 1,2
    waitinput 1000
    hanoi4(n&,1,4,3,2)
    beep
    waitinput
    end

    proc hanoi4 :parameters n&,von&,ueber&,ueber2&,nach&

        if n&=1

            move(von&,nach&)

        elseif n&=2

            move(von&,ueber&)
            move(von&,nach&)
            move(ueber&,nach&)

        else

            Hanoi4(n&-2,von&,ueber2&,nach&,ueber&)
            move(von&,ueber2&)
            move(von&,nach&)
            move(ueber2&,nach&)
            Hanoi4(n&-2,ueber&,von&,ueber2&,nach&)

        endif

    endproc

    '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,4: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 11
Computer: Gerät, daß es in Mikrosekunden erlaubt, 50.000 Fehler zu machen, zB 'daß' statt 'das'...
05/16/21  
 



Zum Experiment


Topictitle, max. 100 characters.
 

Systemprofile:

no Systemprofil laid out. [anlegen]

XProfan:

 Posting  Font  Smilies  ▼ 

Please register circa a Posting To verfassen.
 

Topic-Options

670 Views

Themeninformationen

this Topic has 1 subscriber:

p.specht (1x)


Admins  |  AGB  |  Applications  |  Authors  |  Chat  |  Privacy Policy  |  Download  |  Entrance  |  Help  |  Merchantportal  |  Imprint  |  Mart  |  Interfaces  |  SDK  |  Services  |  Games  |  Search  |  Support

One proposition all XProfan, The there's!


My XProfan
Private Messages
Own Storage Forum
Topics-Remember-List
Own Posts
Own Topics
Clipboard
Log off
 Deutsch English Français Español Italia
Translations

Privacy Policy


we use Cookies only as Session-Cookies because of the technical necessity and with us there no Cookies of Drittanbietern.

If you here on our Website click or navigate, stimmst You ours registration of Information in our Cookies on XProfan.Net To.

further Information To our Cookies and moreover, How You The control above keep, find You in ours nachfolgenden Datenschutzerklärung.


all rightDatenschutzerklärung
i want none Cookie