Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Recursion is simply put the ability of a function to recursively call itself. Re

ID: 673789 • Letter: R

Question

Recursion is simply put the ability of a function to recursively call itself. Recursion is quite easy and also quite practical. Just don't forget to put in an exit clause to your recursive functions or you will find yourself staring at a spinning hourglass while the algorithm chews up all your available resources.

The classic example of a recursive solution to a relatively complex problem is the Tower of Hanoihttps://en.wikipedia.org/wiki/Tower_of_Hanoi - which is taught in every Computer Science program and in a lot of programming classes. As you add disks the solution becomes more complex, but it is a simple repetition of moves used in the 3 disk solution.

We are not going to solve Tower of Hanoi, you are simply going to write a program in Javascript using JSFiddle to demonstrate computational complexity. Using the wikipedia article I want you to write a computer program that calculates the number of moves necessary to solve Tower of Hanoi given a number of disks. Should we be concerned with concerned with the legend of the world ending when the 64 disk solution is physically solved?) Please include screenshots and / or temples of the Javascript code. Thank you!

Explanation / Answer

HTML CODE

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>The Towers of Hanoi</title>
<meta name="description" content="A site providing several variations on the
classic Towers of Hanoi puzzle and a graphic solver." />
<meta name="keywords" content="the, towers, of, hanoi, puzzle, classic,
variations, disk, disks, multistack, solver" />
<meta name="author" content="Brandon Evans" />
<meta http-equiv="Content-Type" content="application/xhtml+xml; charset=utf-8"
/>
<link href="style.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="http://brandonevans.org/hanoi/js/jquery.js"></script>
<script type="text/javascript" src="http://brandonevans.org/hanoi/js/json2.js"></script>
<script type="text/javascript" src="http://brandonevans.org/hanoi/js/sylvester.js"></script>
</head>
<body>
<div>
    <script type="text/javascript">
    <script type="text/javascript"
    src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
    </script>
</div>
<h1>The Towers of Hanoi </h1>
<h3>
    A site containing several variations on the classic Towers of Hanoi puzzle
    and a graphic solver.
</h3>
<p>
    <a href="http://en.wikipedia.org/wiki/Tower_of_Hanoi" target="_blank">The
    Tower of Hanoi</a>
</p>
<div class="yesscript">
    <div id="towers"></div>
    <div></div>
    <table>
        <tr>
            <td><label for="variation">Variation</label></td>
            <td>
                <select id="variation">
                    <option>Classic</option>
                </select>
            </td>
            <td rowspan="11">
                <textarea class="source" id="source"
                rows="20" cols="80"></textarea>
            </td>
        </tr>
        <tr>
            <td><label for="mode">Mode</label></td>
            <td>
                <select id="mode">
                    <option>Wait</option>
                    <option>Repeat</option>
                    <option>Increase</option>
                </select>
            </td>
        </tr>
        <tr>
            <td><label for="diskcount">Disks per Stack</label></td>
            <td>
                <input type="text" id="diskcount" />
            </td>
        </tr>
        <tr class="antwerp">
            <td><label for="towersper">Towers per Stack</label></td>
            <td>
                <input type="text" id="towersper" />
            </td>
        </tr>
        <tr class="antwerp">
            <td><label for="stackcount">Stacks</label></td>
            <td>
                <input type="text" id="stackcount" />
            </td>
        </tr>
        <tr>
            <td><label for="delay">Delay</label></td>
            <td>
                <input type="text" id="delay" />
            </td>
        </tr>
        <tr>
            <td>Moves</td>
            <td>
                <span id="moves"></span>
            </td>
        </tr>
        <tr>
            <td>Minimum Moves</td>
            <td>
                <span id="minimum"></span>
            </td>
        </tr>
        <tr>
            <td>
                <input type="checkbox" id="draw" />
                <label for="draw">Draw</label>
            </td>
            <td>
                <input type="checkbox" id="togglesource" />
                <label for="togglesource">Source</label>
            </td>
        </tr>
        <tr>
            <td>
                <input type="checkbox" id="togglelog" />
                <label for="togglelog">Log</label>
            </td>
            <td>
                <textarea id="log" rows="5" cols="17" readonly="readonly"
               ></textarea>
            </td>
        </tr>
        <tr>
            <td>
                <input type="checkbox" id="togglemovesource" />
                <label for="togglemovesource">Move Source</label>
            </td>
            <td>
                <textarea id="movesource" rows="1" cols="17" readonly="readonly"
               ></textarea>
            </td>
        </tr>
        <tr>
            <td>
                <input type="button" id="switch" value="Start" />
            </td>
            <td>
                <input type="button" id="startover" value="Start Over" />
            </td>
        </tr>
        <tr>
            <td>
                <div class="stopped">
                    <input type="button" id="undo" value="Undo" />
                </div>
            </td>
            <td>
                <div class="stopped">
                    <input type="button" id="redo" value="Redo" />
                </div>
            </td>
            <td class="source">
                <input type="button" id="reload" value="Reload" />
            </td>
        </tr>
    </table>
  
<div>
    <script type="text/javascript">
    </script>
    <script type="text/javascript"
    src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
    </script>
</div>
</body>
</html>

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote