12/27/2023 0 Comments Hanoi towers free![]() This time, you're just moving from peg 1 to peg 2, then when the biggest peg is in place, you're moving the tower from peg 2 to peg 3. We already know how to move a three-disc tower from peg 1 to peg 3. How do you create the three-disc tower? Simple. First create a three-disc tower on peg 2, then move the biggest disc over to peg 3 and move the three-disc tower to peg 3. Then you move the two-disc tower on top of peg 3. Remember the three-disc problem? You first create a two-disc tower on peg 2, which allows you to move the bottommost disc on peg 1 to peg 3. Hint: the problem, like all recursive problems, reduces itself, becoming simpler with each step. If you have a little trouble, keep reading for a small hint. So, if you'd like to challenge yourself, stop reading right here. However, once you get past the hurdle of understanding recursion, the actual coding of the program is relatively simple. Others will have a difficult time with it. Some people will look at this problem and find it extremely easy. For example, a three-disc problem should produce the following output:Īs stated in the section on recursion, recursion is one of the more difficult topics to grasp. Then, print out step-by-step instructions for moving individual discs from one peg to another. First ask the user for the height of the original tower. Your mission, should you choose to accept it - write a program using a recursive procedure to solve the Towers of Hanoi for any number of discs. Now move the two-story tower on top of the large disc: 2 to 1, 2 to 3, 1 to 3. This effectively creates a two-story tower on peg 2. For three discs, you'd move 1 to 3, then 1 to 2, then 3 to 2. The problem gets harder for three or more discs. For two discs, move the topmost disc from peg 1 to peg 2, then 1 to 3, and finally move the smaller disc from 2 to 3. For one disc, you simply move it from peg 1 to peg 3. The problem seems trivial, and it is for one or two discs. In the process, no large disc may be placed on top of a smaller disc, and only one disc (the topmost disc on a peg) may be moved at any one time. The challenge is to move a tower (any height) from peg 1 to peg 3. The pegs are designated 1, 2, and 3 from left to right. For example, this is what a four-story tower looks like: There is a cone-shaped tower on the leftmost peg, consisting of a series of donut-shaped discs. In this problem, you have three vertical pegs. Sometimes, solutions to problems are readily available but we have to figure out a winning strategy and specific action steps ourselves.│ български (bg) │ English (en) │ français (fr) │ 日本語 (ja) │ 中文(中国大陆) (zh_CN) │ĤG - Programming Assignment (author: Tao Yue, state: unchanged)Ī classic recursion problem, taught in all introductory Computer Science courses, is the Towers of Hanoi. Along the way, we must evaluate obstacles, choose among methods for evaluating various decision paths, and compare the effects and trade-offs of each possible move. Developing the strategy involves analysis of the goal to be reached, analysis of the action steps needed, as well as any constraints that may block attainment of the goal. In every day activities, we must often develop a strategy to solve a problem. You use your executive functions when managing your time, planning a presentation or a pairing menu, outlining a report or even taking care of several children simultaneously. The area of the brain at play is the pre-frontal cortex, the anterior portion of the frontal lobe important for the "higher cognitive functions" and the determination of personality. Training in this kind of thinking is helpful as a guide to use in other problem-solving situations. You must define a strategy to reach a desired outcome, calculate the right moves to reach the solution in the shortest possible time, and remember the rules of the exercise. This game requires problem-solving skills that call on the brain's executive functions. From time to time, a given peg may not hold any rings: you may move any available ring you like on to an open space. You can move the top-most ring on each peg to another peg, but you can only move one ring at a time and you can never put a larger ring on top of a smaller ring. In this game, you must configure colored rings on a series of pegs in order to match a target. Before you try to figure out how the Egyptians built the pyramids, try out your problem-solving skills with this game.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |