How to resolve the algorithm Towers of Hanoi step by step in the PureBasic programming language

Published on 12 May 2024 09:40 PM

How to resolve the algorithm Towers of Hanoi step by step in the PureBasic programming language

Table of Contents

Problem Statement

Solve the   Towers of Hanoi   problem with recursion.

Let's start with the solution:

Step by Step solution about How to resolve the algorithm Towers of Hanoi step by step in the PureBasic programming language

Source code in the purebasic programming language

Procedure Hanoi(n, A.s, C.s, B.s)
  If n
    Hanoi(n-1, A, B, C)
    PrintN("Move the plate from "+A+" to "+C)
    Hanoi(n-1, B, C, A)
  EndIf
EndProcedure

Procedure Hanoi(n, A.s, C.s, B.s)
  If n
    Hanoi(n-1, A, B, C)
    PrintN("Move the plate from "+A+" to "+C)
    Hanoi(n-1, B, C, A)
  EndIf
EndProcedure

If OpenConsole()
  Define n=3
  PrintN("Moving "+Str(n)+" pegs."+#CRLF$)
  Hanoi(n,"Left Peg","Middle Peg","Right Peg")
  PrintN(#CRLF$+"Press ENTER to exit."): Input()
EndIf

  

You may also check:How to resolve the algorithm Stack step by step in the Liberty BASIC programming language
You may also check:How to resolve the algorithm Variable size/Get step by step in the BASIC programming language
You may also check:How to resolve the algorithm MD5/Implementation step by step in the Mathematica/Wolfram Language programming language
You may also check:How to resolve the algorithm Boolean values step by step in the MUMPS programming language
You may also check:How to resolve the algorithm Generate Chess960 starting position step by step in the Elixir programming language