Question
Reve's puzzle is identical to the towers of Hanoi problem, except that there are 4 poles (instead of 3) The task is to move n discs of different sizes from the starting
pole to the destination pole, while obeying the following rules:
Move only one disc at a time.
Never place a larger disc on a smaller one.
The following remarkable algorithm, discovered by Frame and Stewart in 1941, transfers n discs from the starting pole to the destination pole using the fewest moves (although this fact was not proven until 2014).
Let k denote the integer nearest to n + 1 - √2n+1
Transfer (recursively) the k smallest discs to a single pole other than the start or destination poles.
Transfer the remaining n - k disks to the destination pole (without using the pole that now contains the smallest k discs). To do so, use the algorithm for the 3-pole towers of Hanoi problem
Transfer (recursively) the k smallest discs to the destination pole.
Write a program vesPuzzle java that takes an integer command-line argument n and prints a solution to Reve's puzzle Assume that the the discs are labeled in increasing order of size from 1 to n and that the poles are labeled A, B, C, and D, with A representing the starting pole and D representing the destination pole. Here are a few sample executions:
Recursive plan for Reve's Puzzle
/Desktop/recursion> java introcs RevesPuzzle 3
Move disc 1 from A to B
Move disc 2 from A to C
Move disc 3 from A to D
Move disc 2 from C to D
Move disc 1 from B to D
Solution Preview

These solutions may offer step-by-step problem-solving explanations or good writing examples that include modern styles of formatting and construction of bibliographies out of text citations and references.
Students may use these solutions for personal skill-building and practice.
Unethical use is strictly forbidden.

/**
    * Recursive Tower of Hanoi (with 3 poles) method
    * from --> mean start
    * to   --> mean destination
    */
    private static void hanoi(int n, int k, String from, String temp, String to) {
       if (n == 0) {
            System.out.println();
            return;
       }
       hanoi(n - 1, k, from, to, temp);
       System.out.print("Move disc " + (n + k) + " from " + from + " to " + to);
       hanoi(n - 1, k, temp, from, to);
    }

    /**
    * The 4 poles version.
    */
    private static void rev(int n, String from, String temp1, String temp2, String to) {
       if (n == 0) return;
This is only a preview of the solution.
Please use the purchase button to see the entire solution.
By purchasing this solution you'll be able to access the following files:
Solution.java
Purchase Solution
$24.00
Google Pay
Amazon
Paypal
Mastercard
Visacard
Discover
Amex
View Available Computer Science Tutors 645 tutors matched
Ionut
(ionut)
Master of Computer Science
Hi! MSc Applied Informatics & Computer Science Engineer. Practical experience in many CS & IT branches.Research work & homework
5/5 (6,807+ sessions)
1 hour avg response
$15-$50 hourly rate
Pranay
(math1983)
Doctor of Philosophy (PhD)
Ph.D. in mathematics and working as an Assistant Professor in University. I can provide help in mathematics, statistics and allied areas.
4.6/5 (6,696+ sessions)
1 hour avg response
$40-$50 hourly rate
Leo
(Leo)
Doctor of Philosophy (PhD)
Hi! I have been a professor in New York and taught in a math department and in an applied math department.
4.9/5 (6,468+ sessions)
2 hours avg response

Similar Homework Solutions