xref: /openbsd-src/regress/usr.bin/bc/t18.in (revision 14d3a4a42a2db0b33fac1a1e976bdb3cdee076e6)
1/* $OpenBSD: t18.in,v 1.1 2003/12/09 12:49:01 otto Exp $ */
2/*
3 * Copyright (c) 2003 Amit Singh <amit_s@acm.org>
4 *
5 * Permission to use, copy, modify, and distribute this software for any
6 * purpose with or without fee is hereby granted, provided that the above
7 * copyright notice and this permission notice appear in all copies.
8 *
9 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16 */
17
18/*
19 * The Towers Of Hanoi
20 * bc version
21 * http://hanoi.kernelthread.com
22 */
23
24define moveit(i, j) {
25  print "move "
26  print i
27  print " --> "
28  print j
29  print "\n"
30}
31
32define dohanoi(n, h, d, o) {
33  if (n > 0) {
34    silence = dohanoi(n-1, h, o, d)
35    silence = moveit(h, d)
36    silence = dohanoi(n-1, o, d, h)
37  }
38}
39
40define hanoi(n) {
41  silence = dohanoi(n, 1, 3, 2)
42}
43
44hanoi(5)
45
46