about summary refs log tree commit diff
path: root/usth/ICT2.1/labwork/4/Bonus.c
blob: b46b3fec89bcb08119af89e4aa2506fca7ebe36c (plain) (blame)
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
/*
 * Solve Towers of Hà Nội of height n, where towers are named foo, bar and baz.
 * This is free and unencumbered software released into the public domain.
 */

#include <stdio.h>

void anoi(unsigned n, char *one, char *other, char *another)
{
	if (n == 0)
		return;

	anoi(n - 1, one, another, other);
	printf("Move from %s to %s\n", one, other);
	anoi(n - 1, another, other, one);
}

int main()
{
	unsigned n;

	scanf("%u", &n);
	anoi(n, "foo", "bar", "baz");

	return 0;
}