subject

Java: Towers of Hanoi Variant

Consider the following variant of the towers of Hanoi problem, There are 2n discs of increasing size stored on the three poles. Initially all of the discs with odd size (1, 3,..., 2n-1) are piled on the left pole from top to bottom in increasing order of size; all of the discs with even size (2, 4, ..., 2n) are piled on the right pole. Write a program to provide instructions for moving the odd discs to the right pole and the even discs to the left pole, obeying the same rules as for towers of Hanoi (The towers of Hanoi provided below)

public class TowersOfHanoi {

// print out instructions for moving n discs to
// the left (if left is true) or right (if left is false)
public static void moves(int n, boolean left) {
if (n == 0) return;
moves(n-1, !left);
if (left) StdOut. println(n + " left");
else StdOut. println(n + " right");
moves(n-1, !left);
}

public static void main(String[] args) {
int n = Integer. parseInt(args[0]);
moves(n, true);
}

}

ansver
Answers: 2

Another question on Computers and Technology

question
Computers and Technology, 22.06.2019 11:00
When building customer relationships through email what should you not do? question 2 options: utilize proper grammar, spelling, and punctuation type in all capital letters use hyperlinks rather than attachments respond to all emails within 24 hours
Answers: 1
question
Computers and Technology, 22.06.2019 17:30
1. before plugging in a new device to a computer you should unplug all other devices turn off the computer turn on the computer 2. many of the maintenance tools for a computer can be found in the control panel under administrative tools display personalization
Answers: 1
question
Computers and Technology, 22.06.2019 22:30
The qwerty keyboard is the most common layout of keys on a keyboard
Answers: 3
question
Computers and Technology, 23.06.2019 12:20
When guido van rossum created python, he wanted to make a language that was more than other programming languages. a. code-based b. human-readable c. complex d. functional
Answers: 1
You know the right answer?
Java: Towers of Hanoi Variant

Consider the following variant of the towers of Hanoi prob...
Questions
question
Mathematics, 02.12.2020 19:20
question
Mathematics, 02.12.2020 19:20
question
Physics, 02.12.2020 19:20
question
Mathematics, 02.12.2020 19:20