Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Text;
- using static System.Console;
- namespace Hanoi
- {
- internal class Program
- {
- private const int SCHEIBEN = 8;
- private static int SCHRITT = 1;
- private static readonly StringBuilder SB = new StringBuilder();
- private static void Main(string[] args)
- {
- Hanoi(SCHEIBEN, 'A', 'B', 'C');
- WriteLine(SB);
- ReadLine();
- }
- private static void Hanoi(int scheibe, char start, char puffer, char ziel)
- {
- if (scheibe == 1)
- {
- Add(scheibe, start, ziel);
- } else
- {
- Hanoi(scheibe - 1, start, ziel, puffer);
- Add(scheibe, start, ziel);
- Hanoi(scheibe - 1, puffer, start, ziel);
- }
- }
- private static void Add(int scheibe, char start, char ziel) =>
- SB.AppendLine($"Schritt #{SCHRITT++:d4} : Bewege Scheibe #{scheibe:d2} von {start} nach {ziel}.");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement