summaryrefslogtreecommitdiff
path: root/rushs/evalexpr/hanoi/hanoi.c
blob: 6ac2b71dbea97ce22b4c459fc52434264e77179d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#include <stdio.h>

void move(unsigned src, unsigned spare, unsigned dst, unsigned n)
{
    if (n == 0)
    {
        return;
    }

    move(src, dst, spare, n - 1);

    printf("%u->%u\n", src, dst);

    move(spare, src, dst, n - 1);
}

void hanoi(unsigned n)
{
    if (n == 0)
    {
        return;
    }

    move(1, 2, 3, n);
}

int main(void)
{
    hanoi(3);
    return 0;
}