about summary refs log tree commit diff
path: root/usth/ICT2.1/labwork/4/Bonus.c
diff options
context:
space:
mode:
Diffstat (limited to 'usth/ICT2.1/labwork/4/Bonus.c')
-rw-r--r--usth/ICT2.1/labwork/4/Bonus.c26
1 files changed, 26 insertions, 0 deletions
diff --git a/usth/ICT2.1/labwork/4/Bonus.c b/usth/ICT2.1/labwork/4/Bonus.c
new file mode 100644
index 0000000..b46b3fe
--- /dev/null
+++ b/usth/ICT2.1/labwork/4/Bonus.c
@@ -0,0 +1,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;
+}