using System;
using System.Windows.Forms;

namespace _7_30
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void TowerOfHanoi(int n, char source,
                                  char temp, char destination)
        {
            if (n == 1)
                listBox1.Items.Add("Move a disk from " + source +
                                   " to " + destination);
            else
            {
                TowerOfHanoi(n - 1, source, destination, temp);

                listBox1.Items.Add("Move a disk from " + source +
                                   " to " + destination);

                TowerOfHanoi(n - 1, temp, source, destination);
            }
        }

        private void button1_Click(object sender, EventArgs e)
        {
            if (textBox1.Text != string.Empty)
            {
                listBox1.Items.Clear();
                TowerOfHanoi(Convert.ToInt32(textBox1.Text), 'A', 'B', 'C');
            }
            else
            {
                MessageBox.Show("تعداد دیسک‌ها را وارد کنید");
                textBox1.Focus();
            }
        }
    }
}