V. ]]>

More generally, we could add the edge case check for n>(k-1)*d, in which case p(k,n)=1 by the pigeonhole principle, but the simple array indexing in the example code won’t work to extract the corresponding generating function coefficient (which is zero).

]]>Anyway you have a error:

>>> p(1,100)

Traceback (most recent call last):

File “”, line 1, in

File “”, line 6, in p

IndexError: index 100 is out of bounds for axis 0 with size 1

>>> p(2,100)

0.9999996927510721

Here is the discrete event simulation; with events in the queue ordered first by time, then by priority… but with no other assumption about “stability” (i.e., extraction in insertion order, etc.), the idea is to use the priority to indicate the number of laps completed. This realizes version A (if lesser priority is extracted first); for version B, just negate the priorities.

]]>