-
Notifications
You must be signed in to change notification settings - Fork 6
/
p92.re
113 lines (109 loc) · 2.14 KB
/
p92.re
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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
/* Von Koch's conjecture */
let get_nodes =
List.fold_left(
(l, (x, y)) =>
(
if (List.mem(x, l)) {
[]
} else {
[x]
}
)
@ (
if (List.mem(y, l)) {
l
} else {
[y, ...l]
}
),
[]
);
let gen_list = (n) => {
let rec gen_list = (n, l) =>
if (n < 1) {
l
} else {
gen_list(n - 1, [n, ...l])
};
gen_list(n, [])
};
let rem_mem = (x) =>
List.fold_left(
(l, y) =>
if (x == y) {
l
} else {
[y, ...l]
},
[]
);
let iter_rmd = (f) => {
let rec iter_rmd = (f, p, l) =>
switch l {
| [] => ()
| [h, ...t] =>
f(p, h, t);
iter_rmd(f, p @ [h], t)
};
iter_rmd(f, [])
};
let vankoch = (tree) => {
let nodes = get_nodes(tree);
let edges = gen_list(List.length(nodes) - 1);
/* tree, current node, current number, visited edges, nodes and edges left */
let rec vankoch = (t, v, n, e, enum) =>
if (t == []) {
List.iter(((i, n)) => Printf.printf("(%d,%d) ", i, n), enum);
Printf.printf("\n");
flush(stdout)
} else {
let (x, y) = List.find(((x, y)) => List.mem(x, v) || List.mem(y, v), t);
let rem_edges =
List.fold_left(
(t, (u, v)) =>
if (x == u && y == v) {
t
} else {
[(u, v), ...t]
},
[],
t
);
let (x, y) =
if (List.mem(x, v)) {
(x, y)
} else {
(y, x)
};
let i =
List.fold_left(
(i, (z, h)) =>
if (z == x) {
h
} else {
i
},
0,
enum
);
iter_rmd(
(p, h, t) => {
let d = abs(i - h);
if (List.mem(d, e)) {
vankoch(rem_edges, [y, ...v], p @ t, rem_mem(d, e), [(y, h), ...enum])
} else {
()
}
},
n
)
};
if (tree == []) {
()
} else {
iter_rmd(
(p, h, t) => vankoch(tree, [List.hd(nodes)], p @ t, edges, [(List.hd(nodes), h)]),
nodes
)
}
};