A long-term project is to turn my Combinatorics course, lectured since 2010 at Royal Holloway, into a textbook. Here is an early draft. Comments are very welcome.

There will be a few computational exercises. As my attempt at one of them, here is a Javascript implementation of the Berlekamp–Massey algorithm. Enter a sequence defined by a linear recurrence below and the algorithm will output its generating function. For example, run on 0, 1, 1, 1, 2, 4, 7, 12, 21, the output is

*x*-

*x*

^{2}) / (1 - 2

*x*+

*x*

^{2}-

*x*

^{3})

where the denominator encodes the recurrence *a*[*n*] = 2*a*[*n*-1] - *a*[*n*-2] + *a*[*n*-3].