Rebol3 Code Examplex
Catalan numbers
Generate the Catalan sequence and use it for combinatorial counting.
Rebol [
title: "Rosetta code: Catalan numbers"
file: %Catalan_numbers.r3
url: https://rosettacode.org/wiki/Catalan_numbers
]
catalan: func [
"Compute the nth Catalan number recursively"
n [integer!]
][
either zero? n [1][
(catalan n - 1) * (4 * n - 2) / (n + 1)
]
]
for n 0 15 1 [
print [
pad n 5
pad catalan n -20
]
]Output:
0 1
1 1
2 2
3 5
4 14
5 42
6 132
7 429
8 1430
9 4862
10 16796
11 58786
12 208012
13 742900
14 2674440
15 9694845