Jump to content

A little help with recursion.

I'm working on an assignment now, and I've been stuck on this for a while. The idea is to implement the frame-stewert algorithm to solve reeve's puzzle (tower of hanoi with 4 towers) 

 

my first attempt didn't work so well ( it would stop halfway) and I know something is really wrong. I tried searching the web for a pseudocode implementation to get an idea of what i'm supposed to be doing, but I didn't have any luck

 

if anyone could explain how the algorithm works, it would really be a lifesaver. i got to get this done in 1 day so i have 24 hours to debug and submit.

Link to comment
Share on other sites

Link to post
Share on other sites

alright, i didn't really understand 100% how it works, but i think that it is just as "simple" as the wikipedia explaination makes it look

it's just a "take a big tower, and break it into small towers, until you have disks, and you know how to move a disk"

 

trying to understand it, i just took an implementation from http://stackoverflow.com/questions/3607161/towers-of-hanoi-with-k-pegs and made it run

if it can help, i uploaded it here http://chuk.altervista.org/areaProgetti/ciao.html

 

the thing that is driving me crazy is the "n-2" thing, for how i understood the algorithm it should work with a "n-1" too, but if i put a "n-1" there, everything goes bananas

Link to comment
Share on other sites

Link to post
Share on other sites

The problem is that to understand recursion one must first understand recursion.

 

post-37426-0-90306100-1393125514.jpg

 

Sorry for not being constructive.

 

Desktop: Intel Core i7-6700K, ASUS Z170-A, ASUS STRIX GTX 1080 Ti, 16GB DDR4 RAM, 512 GB Samsund 840 Pro, Seasonic X series 650W PSU, Fractal Design Define R4, 2x5TB HDD

Hypervisor 1: Intel Xeon E5-2630L, ASRock EPC612D8, 16GB DDR4 ECC RAM, Intel RT3WB080 8-port RAID controller plus expansion card, Norco RPC-4020 case, 20x2TB WD Red HDD

Other spare hypervisors: Dell Poweredge 2950, HP Proliant DL380 G5

Laptops: ThinkPads, lots of ThinkPads

 

Link to comment
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×