Jump to content

Torres de Hanoi


disasterpiece
 Share

Recommended Posts

Este código não foi feito por mim, mas é muito giro. É o prograna do conhecido jogo ''Torres de Hanoi''. 😉

Program torreHanoi;
uses wincrt;
var n:integer;

 procedure hanoi(n:integer;a,b,c:char);
 {mova n discos do pino a para o pino b usando o pino c como auxiliar}
 begin
   if n=1
   then writeln('mova o disco ',n,' do pino ',a,' para o pino ',b)
   else
   begin
     hanoi(n-1,a,c,b);
     writeln('mova o disco ',n,' do pino ',a,' para o pino ',b);
     hanoi(n-1,c,b,a)
   end
 end;

begin
 read(n);
 hanoi(n,'A','B','C')
end.
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...

Important Information

By using this site you accept our Terms of Use and Privacy Policy. We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.