Difficult program design

i have a question here. It is a quite difficult program design for me. Any body can help me?
As legend has it, some priests in the Far East endeavored to move a stack of disks from one peg to another. There were 64 disks in all. Each had a unique diameter. They were stacked in order of diameter from the largest on the bottom to the smallest on the top. Three pegs were available, with the stack beginning on peg 1. The stack needed to be moved to peg 3. The restrictions were that only one disk could be moved at a time, and that a disk could not be placed upon another that was smaller. The legend claims that if and when completed, the world would end.
To speed the onset of Armageddon, complete a Java program that solves the Towers of Hanoi. Two methods need to be implemented to complete the class TowersOfHanoi. The method main must prompt the user for the number of disks with which to run the simulation. Store the input into the variable numDisks, which is already declared in the method main. Assume the input will be a positive integer.
The method move is the workhorse, and must be implemented recursively. Its prototype follows.
protected static void move(int n, int from, int to, int temp);
The first parameter is the number of disks to move. The second is the peg upon which the disks to be moved currently reside. The third is the peg onto which those disks will be moved. The fourth is the extra peg, used as a temporary holding spot to facilitate the move. The method move must implement the following formula.
Formula to Move n Disks
move n - 1 disks to the temporary peg
move 1 disk to the destination peg
move n - 1 disks to the destination peg
Picture moving the stack by hand, disregarding, for now, the restriction that only one disk can be moved at a time. To move a stack of n disks, grab all but the last disk and place that sub-stack onto the temporary peg. Move that last (largest) disk to the destination peg. Grab the sub-stack from the temporary peg and move it on top of the (largest) disk now residing on the destination peg. The restriction that a larger disk couldn't be placed upon a smaller one has not been violated. The recursion comes into play in the part where the sub-stack is moved. To move a stack of n disks requires, based on the formula, moving a stack of n - 1 disks. This smaller task can be solved with the same formula. The new (smaller) task becomes moving n - 1 disks from one peg to another. The base case occurs when the method move is called to move just one disk (when the parameter n is 1). During, and only during, the invocation of the method move in which the parameter n is 1, the method move must print a line of instruction describing the move, as in the following example.
Move top disk from peg <from> to peg <to>
<from> is simply the second parameter of the method move, and <to> is the third. The fourth parameter, the temporary peg, is not used in the output.

Looks a bit like homework, tell us how far you've got and which particular points you're stuck on and people might be willing and able to help.
Actually I suspect if you search Google for 'Tower of Hanoi' you'll probably find lots of help.

Similar Messages

  • Course material : SQL Programming & Design

    Hello,
    Monday I have an exam of SQL Programming & Design, witch I followed online on the oracle academy site. Now I see that the website is down! Is there a opportunity to view the course material?
    Greetz,
    Dries

    Hi Bjarne
    Thankyou for the content.  I always find it informative and of quality.  I point my students to your site in my BI class.
    At the moment there are discussions happenning about accessing Teched workshops on topics like Xcelsius and Visual composer.  These being available to academics will compliment your presentation.
    Well done
    Paul Hawking
    Academic Program Director
    Victoria University
    SAP Mentor

  • Program design books or links

    I am stuggling with program design. For example how much is good to incorporate into a single class. For example in the constructor for a Transaction claass I have the constructor looking up the last TransactioniID by reading the last transaction in the file.
    Then I want to calculate different values for the transaction class instance variables but to do this I need to access the client class object to find specif argument values
    So I created another class to do caluulatios using values from both the Client class and the transacrion class. This class I called Time.
    I looked at Violet but am not sure how this well help. It�s a small-small app at this point and I am asking if anyone is willing to look at the project? Or jugest program design links, books for a begginer.
    Mic.

    There's a decent Sybex book... it's called UML with Rational Rose, I think.
    When it comes right down to it, Rose is just another UML diagramming program like any other. Learn the intricacies of UML, and you're gonna have Rose pretty much down.

  • XML and its influence over program design (2 issues)

    I have 2 open questions about XML and Java. I apologise if they are not clear-cut or specific enough, but really I am fishing for sound advice.
    I am trying to develop a J2EE application but find myself stuttering at an early stage because I cannot decide on the best design for my application. Part of my problem is a lack of experience with the different J2EE technologies/API (especially XML APIs), and the realisation that there is 101 ways to do what I want to do.
    A major issue is this: my application basically is concerned with representing conversations between the server and a user, e.g. a simple sequence of yes/no questions asked by the server to the user, which the user replies to in turn. I believe that the XML format would be a very suitable way to represent these conversations. My first question is:
    * Should the decision to use XML as a storage format influence the design of the rest of the program? I feel that in choosing XML to represent the conversation data, I am stuck thinking about the rest of my program in a XML way (i.e. doing everything using a DOM etc.). Am I right in thinking that my program should be designed in such a way that an XML-based storage system could be easily interchanged with, say, a relational flat-tabled database?
    My second question is:
    * Imagine that each conversation contains one or more questions, and there are, say, 4 different types of question (e.g. yes/no, multiple choice, etc.). Each of these needs to be handled in a different way. Is there a good pattern or recommended way of handling this sort of situation in code, ideally avoiding a big 'if' or switch statement (e.g. if the node is of "ABC" type do this, else if it is "yes/no"...). It would be great if one could easily add new types of question to the XML and then similarly one can make easy additions to the code to cope with these new cases.
    Thank you very much indeed for any advice.
    Greg

    I am trying to develop a J2EE application but find
    myself stuttering at an early stage because I cannot
    decide on the best design for my application. Part of
    my problem is a lack of experience with the different
    J2EE technologies/API (especially XML APIs), and theThat's nothing to be ashamed of. And realising that you lack experience and trying to remedy that is a good sign.
    A major issue is this: my application basically is
    concerned with representing conversations between the
    server and a user, e.g. a simple sequence of yes/no
    questions asked by the server to the user, which the
    user replies to in turn. I believe that the XML
    format would be a very suitable way to represent
    these conversations. My first question is:
    XML might be overkill if it's just a question followed by an answer and neither contains complex hierarchical data structures.
    * Should the decision to use XML as a storage format
    influence the design of the rest of the program? ICertainly not.
    XML should represent data structures that are natural to your program, thus becoming a tool rather than forcing its structure upon you.
    feel that in choosing XML to represent the
    conversation data, I am stuck thinking about the rest
    of my program in a XML way (i.e. doing everything
    using a DOM etc.). Am I right in thinking that my
    program should be designed in such a way that an
    XML-based storage system could be easily interchanged
    with, say, a relational flat-tabled database?
    Flexibility is good to keep in mind, but at the moment I'd worry about just getting something to work.
    * Imagine that each conversation contains one or more
    questions, and there are, say, 4 different types of
    question (e.g. yes/no, multiple choice, etc.). Each
    of these needs to be handled in a different way. Is
    there a good pattern or recommended way of handling
    this sort of situation in code, ideally avoiding a
    big 'if' or switch statement (e.g. if the node is of
    "ABC" type do this, else if it is "yes/no"...). It
    would be great if one could easily add new types of
    question to the XML and then similarly one can make
    easy additions to the code to cope with these new
    cases.
    Think of a factory that creates the handlers on the fly based on the actual message received.
    If the factory makes use of some mapping construct to do so there's no need for any conditionals at all in your decision tree.
    I've myself used XML structures successfully to define such mappings (and so have others) on disc, but simple ones can be easily represented using just a properties file.

  • Program Design Problem: Inner Class use verse interacting seperate classes?

    i am designing a GUI based program that needs to have 2+ windows that interact with each other. In my original design there were just two windows: the World display, and the tile choser (this is for 2D map editing). Because there were only 2, I made them both inner classes of another class. The top level class's fields were how I got the two windows to interact.
    Now I am adding more tile choser esque windows and it is getting very confusing and the amount of Fields is getting ridiculous and the whole thing isnt very OO.
    I thought about splitting up the World Display window and the Tile Choser window into two different classes and just have multiple instances of the Tile Choser class for the additional windows.
    The problem is the interaction. I could pass all of the variables that both classes require to constructers and set up lots and lots of get and set methods, but then that seems to destroy the whole idea of two classes. The whole project is getting really messy.
    Any thoughts?
    I know that was a jarbled explanation so just ask about any part that might be unclear

    Create an object that represents the state being manipulated. The model.
    Create methods to modify that data. Not getters/setters, but controllers. If it's a map, then maybe a method would be "addTown" or something. This represents the controller.
    Create methods to render the data graphically. The views.
    Pass this object to GUI widgets, or reference it from inner event handlers.

  • Program design

    This is a simple question. I'm planning a program right now. It's going to be a crippled language translator with limited words. My problem is the design. How should I go about separating the gui from the code? And what should happen in my main method -- only method/class instantiation -- or other code? Thanks

    Your main method will probably instantiate the class(es) with the main application logic, create the GUI, and tie the two together.
    You might create a different UI (say, a command-line UI) with its own main method, and which does roughly the same thing only it would create the command line processor rather than a GUI.
    To keep the UI seperate from the main application, don't even write the GUI at first. Drive your application with test classes. When you get it working, you then might want to create a command-line UI (it's good for further testing), and then finally create your GUI.

  • Running programs designed for 10g Ex on 11g Ex

    I am one of those individuals who over the last couple years has been frustrated because of Oracle 10g will not run on 64bit Windows. I use a Oracle 10g Ex based program that was developed by a third party. It runs successfully on a ADM 64 bit system that runs Windows XP (not 64 bit Windows). All attempts to get it to run on Windows Vista or Windows 7 64 bit have failed. I seen on a separate post that the final version of 11g Ex is expected to run on 64 bit. Does that mean that any program that could used 10g Ex can now use 11g Ex.

    Basically, I'd say yes. Some things changed a little bit from 10g to 11g, e.g. the case sensitive password handling, some parameters, etc., so there might be a few points to reconfigure in your applications... You might get a more precise answer if you outline which database features your applications use right now.
    -Udo

  • Program design flaw in After Effects - Position

    I am having a heck of a time getting my credits to scroll up properly. A major problem is the program automatically adds a keyframe point every time one moves things. My credits start and stop at bizarre places, and at more places than there appears to be key frames,or they go in the wrong direction and then change direction on their own accord. And the process of placing or modifying the start and finish positions of the text is not at all intuitive. I cannot even figure out whether the first keypoint is supposed to be the start, or finish point.Yes, I've watched the videos, and read the help, but I would be grateful for some simple instruction how I can get a long credit to scroll.
    Also, there seems to be no master command to disengage or delete all command information for say position. I have been using the revert function, but one should be able to cancel everything at once if desired.

    I've seen your desperate posts from the past few days, and I gotta tell you: I can feel your pain, but you really are trying to jump into the deep end of the pool, and your lack of basic AE knowledge is like wearing lead weights when you jump in.  It doesn't help that AE is definitely NOT an application you can use intuitively, nor does it help that AE's online help is more of a reference tool than it is a learning tool... Adobe really has to work on that.
    AE has its own way of thinking.  Its own arcane lexicon.  Its own way of solving a problem.  It's really tough for a beginner to grasp that.  While many applications have a quick-start, get-your-feet-wet set of instructions, AE doesn't.  It really demands that you walk before you run, that you learn the basics before you launch off into the fun stuff.  You can't define a trick you want to learn and expect to find a step-by-step how-to.
    So how do you learn the basics?  Forget about AE's online help: as mentioned earlier, it's a reference work, not a textbook.  Here's an example: you can look up "French Language" in the encyclopedia and find a wealth of information about its history, a brief description of syntax, the origin of words, etc. but you won't learn French out of an encyclopedia.  You take a French class, invest in Rosetta Stone, get a French language textbook... a variety of things.  When starting to learn French, you don't make your first project a written critique of the works of Jean-Paul Sartre.  The same applies to learning AE.  It really is a lot like learning a foreign language.
    Here are some other learning options... but they all require learning the basics first: it's a fact of life in AE-Land.
    Todd's Getting Started link is a good beginning point, but it's no good if you're impatient.  You've got to go through it, and not cherry-pick what YOU think is important.  You'll probably be wrong.  There are also certain things that are lacking because it's all free, and the topics can be hit-and-miss.
    You say there's nothing like a book.  Fortunately, two highly-respected AE practitioners, Chris and Trish Meyer, have a set of books available for various AE versions.  They've been with After Effects since Version 1.  With the possible exception of CS 5.5, you'll find a fine "Learn AE" book by the Meyers, and it's just a google away.  The Meyers' books almost always come with footage and project files so you can play along at home.  I swear by these books for identifying the Basic Concepts And Things You Need To Know.  Again, patience is the watchword.
    There are quite a few books out besides the Meyer's works, and I've found them on the shelf at Barnes and Noble.  You can check 'em out yourself.  You might even find one called After Effects For Dummies, and you shouldn't take offense: EVERYBODY'S a dummy when they first begin learning AE.
    Total Training has AE training DVDs, and they're also highly-regarded.  I used them back when I was first learning AE (and I continue to learn AE to this day).  They too come complete with footage and project files.
    Todd and Angie Taylor, also highly-ranked among the Who's Who in the AE community, have training available on DVD:
    http://www.peachpit.com/store/product.aspx?isbn=0321734866
    Many of the lessons Todd links to in his Getting Started section come from this, but you get footage and files with the paid version.  I have this one myself, and I use it.
    Lynda.com also offers AE training, but I've never used it.
    That's a pretty good list of popular ways to learn After Effects, but each one stresses that learning the basics is essential.  Many have tried to learn AE the way you're currently doing it, and they've either failed, given up on AE (a real shame) or accepted that they need to learn it the recommended way.
    While you might not like what I just wrote, that's the situation: you learn AE a certain way, which may not be the way you want.  That's just the truth of it.

  • Help with program design

    I am trying to create a program that exchanges information using UDP with the option to encrypt the information sent, the key used will be exchanged before hand, a wraped key, there is just one problem, the init method on the cipher object. i can't figure out how to initilize it, because I don't have a key until I unwrap it
    andrewjj20

    what are some good websites on encryptionOy. I usually point people at books rather than websites. "Applied Cryptography", by Bruce Schneier, and "Practical Cryptography", by Schneier and Ferguson, are my two standard "read these to know how it works" volumes. Crypto is a large topic.
    When I said "search on" in my message, I meant searching right here in these forums. There's been a lot of discussion on key-exchange in here.
    Good luck,
    Grant

  • Concurrent Programming Design Help

    Hi All,
    Currently we have a program which goes sequentially on the following tasks
    1. Run a SQL query(query 1) and gather results
    2. Run a SQL query(query 2) and gather results
    3. Do a string validation on the data(result set) - Same for the data returned in both the results
    4. calls a web service for all the elements in the result set
    Currently this program is taking around 8 min. I would like to make it parallel, what should be my approach. I am using Java 7
    Thanks in advance

    Currently we have a program which goes sequentially on the following tasks
    1. Run a SQL query(query 1) and gather results
    2. Run a SQL query(query 2) and gather results
    3. Do a string validation on the data(result set) - Same for the data returned in both the results
    4. calls a web service for all the elements in the result set
    Currently this program is taking around 8 min. I would like to make it parallel, what should be my approach. I am using Java 7
    Use a separate thread for each query. Each thread will use its own connection to execute one of the queries and gather the results.
    Step #4 is NOT correct based on what you have posted. It says 'for all the elements in THE result set'.
    You have TWO result sets; one for each query. You have NOT listed anything that combines those into ONE result set.
    If the result sets are distinct then your main thread can begin returning results as soon as ONE of the child threads has produced its result set.
    See the MANY trails on Concurrency in The Java Tutorials
    Lesson: Concurrency (The Java™ Tutorials > Essential Classes)

  • Trouble on program design

    Hi guys, this topic might be on the wrong place but i have this issue for such a long time now and i can't get rid of it..
    While working on the looks of the application you normaly have those blue stripes to set object on the same height..
    Some how i pressed something and now i have those dots allover my form and the stripes dissapeared..
    So i might be the noobie again.. and it probably is verry simple to solve..
    I hope you guys could help me out!
    Regards 

    Menu Tools -> Options -> Windows Forms Designer: LayoutMode = SnapLines
    Armin

  • Is there a way to run a program designed for PC on my Mac?

    I would like to use the Firearms Management System offered by one of my suppliers on my Mac but the only operating system shown to use is with is Windows. Is there a way to run it on my iMac?

    Sure, many:
    (Borrowed from Kappy)
    Windows on Intel Macs
    There are presently several alternatives for running Windows on Intel Macs.
    Install the Apple Boot Camp software.  Purchase Windows XP w/Service Pak2, Vista, or Windows 7.  Follow instructions in the Boot Camp documentation on installation of Boot Camp, creating Driver CD, and installing Windows.  Boot Camp enables you to boot the computer into OS X or Windows.
    Parallels Desktop for Mac and Windows XP, Vista Business, Vista Ultimate, or Windows 7.  Parallels is software virtualization that enables running Windows concurrently with OS X.
    VM Fusionand Windows XP, Vista Business, Vista Ultimate, or Windows 7.  VM Fusion is software virtualization that enables running Windows concurrently with OS X.
    CrossOver which enables running many Windows applications without having to install Windows.  The Windows applications can run concurrently with OS X.
    VirtualBox is a new Open Source freeware virtual machine such as VM Fusion and Parallels that was developed by Solaris.  It is not as fully developed for the Mac as Parallels and VM Fusion.
    Note that Parallels and VM Fusion can also run other operating systems such as Linux, Unix, OS/2, Solaris, etc.  There are performance differences between dual-boot systems and virtualization.  The latter tend to be a little slower (not much) and do not provide the video performance of the dual-boot system. See MacTech.com's Virtualization Benchmarking for comparisons of Boot Camp, Parallels, and VM Fusion. Boot Camp is only available with Leopard or Snow Leopard. Except for Crossover and a couple of similar alternatives like DarWine you must have a valid installer disc for Windows.
    You must also have an internal optical drive for installing Windows. Windows cannot be installed from an external optical drive.

  • A program designed for windows will not install

    I have been trying install the latest version of the Roche Accu-Chek Compass software on my new MacBook with Leopard, Bootcamp and the latest updated version of Windows XP all installed. The installation disk is OK (It installs on another PC OK. Accu-Chek support have been unable to help so far. I wonder if anyone else has had similar problems or can make any suggestions? The install wizard appears to start OK but then stops and a pop-up headed Install Error detected appears, saying "Install encountered an unexpected error please try again"
    Any advice would be much appreciated.

    I have found a solution! Download and install VM Fusions then install Accu-Chek Compass - it then works like a dream. In fact I am delighted with VM Fusions it seems work in the way I had hoped that Bootcamp would. I have obtained the 30 day trial version from
    http://www.vmware.com/products/fusion/
    Hope this helps. ( I have no connection with VM Ware other than as a potential customer)

  • Urgent help on difficult programming  required -remove select statement

    loop at zt_wbs.
      clear   zt_cobrb.
      refresh zt_cobrb.
    Select settlement rules
      select distinct anln1 anln2 from cobrb
             into corresponding fields of table zt_cobrb
             where objnr = zt_wbs-objnr and
                   perbz = 'GES'        and
                   konty = 'AN'.
        if sy-subrc = 0.
          describe table zt_cobrb lines i.
          if i = 1.
        unique settlement rule
            read table zt_cobrb index 1.
            zt_changes-equnr = zt_wbs-equnr.
            zt_changes-anln1 = zt_cobrb-anln1.
            zt_changes-anln2 = zt_cobrb-anln2.
            collect zt_changes.
          endif.
        endif.
    endloop.
    hii...i can modify the structure of table zt_cobrb  if required. please tell me a code in which i can carry my select statements outside the loop.and do the same thing.
    remember there is a distinct keyword after select statement and i have to loop at zt_wbs having one of the fields objnr.

    loop at zt_wbs.
      clear   zt_cobrb.
      refresh zt_cobrb.
    Select settlement rules
      select distinct anln1 anln2 from cobrb
             into corresponding fields of table zt_cobrb
             where objnr = zt_wbs-objnr and
                   perbz = 'GES'        and
                   konty = 'AN'.
        if sy-subrc = 0.
          describe table zt_cobrb lines i.
          if i = 1.
        unique settlement rule
            read table zt_cobrb index 1.
            zt_changes-equnr = zt_wbs-equnr.
            zt_changes-anln1 = zt_cobrb-anln1.
            zt_changes-anln2 = zt_cobrb-anln2.
            collect zt_changes.
          endif.
        endif.
    endloop.
    hii...i can modify the structure of table zt_cobrb  if required. please tell me a code in which i can carry my select statements outside the loop.and do the same thing.
    remember there is a distinct keyword after select statement and i have to loop at zt_wbs having one of the fields objnr.

  • I was online checking flights when a window popped up on my screen saying my computer has been infected by 3 viruses: Backdoor, Adware, and Malware. Does Mac automatically send this alert or is it a program designed to gain access to my system?

    I was online checking for flights when a window popped up on my screen saying my computer had been infected by 3 viruses: Backdoor, Adware, and Malware.  Does Mac automatically send out this alert?  The pop up has a "cleanup button", and is asking me to register some antivirus to enable a full cleanup.  Is this really from Mac/Apple or from some entity trying to gain further entrance to my data?  Can't seem to get assistance from Apple until 6 am.  I am not computer savvy. PLEASE ADVISE!!!

    Do not ignore this... it's malware, not a virus. Even if you didn't click on anything, make sure your Mac is free of malware.
    Follow the instructions from the first two links.
    http://www.fixkb.com/2011/05/remove-mac-protector.html
    http://www.macrumors.com/2011/05/02/new-macdefender-malware-threat-for-mac-os-x/
    And read here.  http://www.reedcorner.net/guides/macvirus/
    Never accept unsolicited offers from the internet.

Maybe you are looking for

  • Changing Headers and Footers in FrameMaker 8

    Our margins for our headers and footers in the template I created are too large; I'd like to change them but simply can't remember how. I've consulted the forums and Adobe Help. I scoured the reference pages to try and jar my memory, but it's not wor

  • HR TABLE

    HII, i want table for field 'HIREDATE' its there in structure 'PRELQ' .

  • Have CS 3; am installing CS 5.5

    Hello, I currently have Web Premium CS3, InDesign 4. I am installing CS 5.5 design premium.  Not an upgrade......purchased through a company that sells reasonably to non-profits. They emailed me the License Key. There are no instructions except on th

  • Material Master - Standard Price

    Please suggest - how to change(update) the "Standard Price" of the material in Accounting view of the Material Master ?

  • Corrupted OS X

    Greetings, My iMac is displaying various symptoms (hanging with the cursor still movable but not functional, hanging with nothing movable, displaying the white screen of death) and my local Geek Squad told me that OS X files must be corrupted. I trie