From 0887d8f96950a060a122e14ed2981182ff1eb37d Mon Sep 17 00:00:00 2001 From: Nguyễn Gia Phong Date: Sat, 28 Dec 2019 21:16:58 +0700 Subject: [usth/ICT2.1] Algorithm and Data Structures --- usth/ICT2.1/labwork/4/Bonus.c | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 usth/ICT2.1/labwork/4/Bonus.c (limited to 'usth/ICT2.1/labwork/4/Bonus.c') 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 + +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; +} -- cgit 1.4.1