After reading John D. Cook’s blog
post on
simulating a random walk around a clock, I wanted to see what a solution in J
would look like.

Let the first row of a state matrix be a count of how many times position j
has been visited, and the second row be a row of zeroes with a one marking the
current position.

Define a random flip function

Define a transition function that increments the position count and shifts
the current position left or right

We want to run this until all positions are visited, i.e. there are no zeroes
in the first row.

The number of steps taken to visit all positions is the sum of the first row.

Now we’re ready to run many simulations and compute the mean number of steps.

I'm a software engineer currently living in Melbourne, working remotely for the
Psychiatry Neuroimaging Laboratory
in Boston and
a startup in Canada. My interests are data analysis pipelines and inference,
and I'm unduly obsessed with understanding design principles behind concise,
uncomplicated software systems.