• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: [OT] Towers of Hanoi with four pegs
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [OT] Towers of Hanoi with four pegs


  • Subject: Re: [OT] Towers of Hanoi with four pegs
  • From: Peter Wollschlaeger <email@hidden>
  • Date: Thu, 29 Apr 2004 23:50:18 +0200

Am 29.04.2004 um 21:15 schrieb Eric Czarny:

> I know this is slightly off topic, but I couldn't find any place else
> to find help. Anyway, for computer science I need to write a recursive
> function to solve the Towers of Hanoi with four pegs. However, I have
> spent all day working on a solution but can't seem to figure it out.
> If any of you have code to solve this problem it would help me out a
> great deal as the assignment is due tonight at 11:59:59 EST.
>
> Thanks!
> Eric Czarny


The following listing is part of my latest C++ book. It has only 3 pegs
but you can choose the number of discs. Hope, it gives you an idea how
to use a recursive function to solve this task.

// Markt+Technik-Verlag
// C++ f|r Einsteiger von Peter Wollschlaeger
// Kapitel 2, Listing 2.23

#include <iostream>
using namespace std;

void hanoi(int s, int l, int m, int r)
{
if(s == 1) {
cout << " " << l << " --> " << r << endl;
return;
}

hanoi(s - 1, l, r, m);
hanoi(1, l, m, r);
hanoi(s - 1, m, l, r);
}

int main()
{
int s;
cout <<"Wie viele Scheiben? ";
cin >> s;
cout << endl
<< "Legen Sie die Scheiben"
<< endl << "von --> auf"
<< endl << endl;
hanoi(s, 1, 2, 3);
return 0;
}


> _______________________________________________
> cocoa-dev mailing list | email@hidden
> Help/Unsubscribe/Archives:
> http://www.lists.apple.com/mailman/listinfo/cocoa-dev
> Do not post admin requests to the list. They will be ignored.
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.


References: 
 >[OT] Towers of Hanoi with four pegs (From: Eric Czarny <email@hidden>)

  • Prev by Date: Re: [OT] Towers of Hanoi with four pegs
  • Next by Date: Re: CamelBones
  • Previous by thread: Re: [OT] Towers of Hanoi with four pegs
  • Next by thread: Re: [OT] Towers of Hanoi with four pegs
  • Index(es):
    • Date
    • Thread