Jump to content


Check out our Community Blogs

Register and join over 40,000 other developers!


Recent Status Updates

View All Updates

Photo
- - - - -

help me to wite these Recursive algorithm...

recursive

  • Please log in to reply
3 replies to this topic

#1 Evangeline

Evangeline

    CC Lurker

  • Just Joined
  • Pip
  • 1 posts

Posted 03 March 2011 - 02:04 AM

hey guys, I have 3 questions, I'm beginner in programming, please help me to write these Recursive algorithm!

in the hannoy tower, we shoud move all the disks to the destination bar, but we are not allowed to move the disks from 1st bar to 3rd directly...

you know horner rule, it's for finding the amount in a special x like x_0 in a Polynomial A(x)=a_n x^n+a_(n-1) x^(n-1)+⋯+a_1 x+a_0
we can also write it like this : A(x_0 )=(…((a_n x_0+a_(n-1) ) x_0+⋯+a_1 )+a_0), i need an Recursive algorithm to calculate it...

and the third one is about combinations, we have n boolian integers, how can i write a programe to show all the combinations?

thank you
  • 0

#2 WingedPanther73

WingedPanther73

    A spammer's worst nightmare

  • Moderator
  • 17757 posts
  • Location:Upstate, South Carolina
  • Programming Language:C, C++, PL/SQL, Delphi/Object Pascal, Pascal, Transact-SQL, Others
  • Learning:Java, C#, PHP, JavaScript, Lisp, Fortran, Haskell, Others

Posted 03 March 2011 - 03:39 AM

Standard response: what do you have so far?
  • 0

Programming is a branch of mathematics.
My CodeCall Blog | My Personal Blog

My MineCraft server site: http://banishedwings.enjin.com/


#3 Flying Dutchman

Flying Dutchman

    CC Leader

  • Expert Member
  • PipPipPipPipPipPipPip
  • 1090 posts
  • Location:::1
  • Programming Language:C++, Python

Posted 03 March 2011 - 05:51 AM

Hint: for the 3rd question, next_permutation could be useful.
  • 0

The roots of education are bitter, but the fruit is sweet.


#4 gregwarner

gregwarner

    Obi Wan of Programming

  • Expert Member
  • PipPipPipPipPipPipPip
  • 1586 posts
  • Location:Arkansas
  • Programming Language:C, Java, C++, C#, PHP, Transact-SQL

Posted 04 March 2011 - 12:59 PM

To help you out, here is the pseudo code for the Towers of Hanoi solution algorithm:

(Assume pegs are labeled s, d, and p, and that n represents the number of discs you wish to move.)

hanoi(source peg [I]s[/I], destination peg [I]d[/I], other peg [I]p[/I], number of disks to move [I]n[/I]) :=

[I]Terminating step:[/I]

if n = 1, move s to d;

[I]Recursive step:[/I]

else,
hanoi(s, p, d, n-1);
move s to d;
hanoi(p, d, s, n-1);

  • 0





Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download