aboutsummaryrefslogtreecommitdiff
path: root/v_windows/v/old/examples/hanoi.v
blob: 0851ba0dd3aa16b1d40670af2a0a4335b1b1a3ab (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
// hanoi tower
const (
	num = 7
)

fn main() {
	hanoi(num, 'A', 'B', 'C')
}

fn move(n int, a string, b string) {
	println('Disc $n from $a to ${b}...')
}

fn hanoi(n int, a string, b string, c string) {
	if n == 1 {
		move(1, a, c)
	} else {
		hanoi(n - 1, a, c, b)
		move(n, a, c)
		hanoi(n - 1, b, a, c)
	}
}