Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

If possible, this tower of hanoi code is written in java. Could anyone make an attempt to write it in python? package Hanoi; import java.util.Scanner;

If possible, this tower of hanoi code is written in java. Could anyone make an attempt to write it in python?

package Hanoi; import java.util.Scanner; private int n,current,r; public class Towers { private Scanner in; private int[] hasItMoved,toDest; Towers(){ this.in=new Scanner(System.in); this.current=1; System.out.println("Enter the number of disks: "); this.n = in.nextInt(); this.hasItMoved=new int[12]; this.toDest=new int[12]; for(int j=0;j 2) { this.current = H1(numOfDisks-1, Start, source, dest, aux,last, this.current); if(this.hasItMoved[numOfDisks]!=1) {move(numOfDisks, Start, source, this.current); this.current++;this.hasItMoved[numOfDisks]=1;} move(numOfDisks, source, aux, this.current); this.current++; this.current = H1(numOfDisks-1,Start, dest, source, aux,last, this.current); move(numOfDisks, aux, dest, this.current); this.current++; if(this.toDest[numOfDisks+1]!=0) {move(numOfDisks, dest, last, this.current); this.current++;this.toDest[numOfDisks]=1;} if(numOfDisks==r) this.r--; this.current = H1(numOfDisks-1, Start,source, dest, aux,last, this.current); }; return this.current; } public void move(int aDisk, String source, String dest, int currentStep) { System.out.println("Move " + this.current + ": Move disk " + aDisk + " from " + source + " to " + dest);}

Hanoi.java

package Hanoi; public class Hanoi { public static void main(String[] args) { Towers test=new Towers();}}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions