Python: Tower of Hanoi
Learning : Python
Subject: Write a Function to Solve Tower of Hanoi Problem
Intoduction: Tower Of Hanoi is Puzzle Game that has three Vertical Sticks/Pegs Named A, B, C (3 Towers) and we have n number of disks different in diameter soted on top of each other (Large to Small) in Tower A. The Gall is to move all the disks from (A) to (C).
# Tower of Hanoi Puzzel """ Project Name: Tower of Hanoi By: Ali Radwani Date: 13.6.2021 d : Number of Desk fs : From Stick ts : To Stick bs : Buffer Stick """ import os def hanoi_t(d, fs, bs, ts): if d ==1 : print("\n Move Desk 1 From {} To {}".format(fs,ts)) return else: hanoi_t(d-1,fs,ts,bs) print(" Move Desk {} From {} To {}".format(d,fs,ts)) hanoi_t(d-1,bs,fs,ts) print(" Move Desk {} From {} To {}".format(d,fs,ts)) os.system('clear') print('\n\n This is Tower Of Hanoi Project') print(' We are Solving a Three Desk Tower Named 1, 2 and 3, with Three Sticks Named A, B and C ') print('\n Start Solving ...') hanoi_t(3,'A','B','C')
![]() |
..:: Have Fun with Coding ::.. 🙂
To Download my Python code (.py) files Click-Here
By: Ali Radwani
Comments (0)
Trackbacks (0)
Leave a comment
Trackback