## The PacMan problem

I came across this mathematical problem the other day: Consider n points on a circle, labeled clockwise from 0 to n -1. Initially PacMan begins at 0 and there is a dot at each of the remaining n -1 points. PacMan takes a random walk around the circle; at each step, it moves with probability 1/2 to one neighbor and with probability 1/2 to the other neighbor. (Note that points 0 and n -1 are neighbors.) The first time PacMan visits any point it eats the dot that is there. Which dot is most likely to...

## JavaScript: Unit testing asynchronous functions

In a previous blog post , I talked about the QUnit unit testing library for JavaScript . In that post, I showed how to use it with a date library I was messing around with. If I were you I would review that previous blog post; it will help in what’s to come. photo © 2011 Derek Gavey | more info (via: Wylio ) Recently, while I was at the Tech·Ed conference working in the DevExpress booth, someone asked me about how to test JavaScript functions that were asynchronous in nature. By this I mean that...

## JavaScript for C# developers: callbacks (part III)

In the previous two installments ( one , two ) we explored the use of callbacks through creating a mapp function for arrays (so called because the latest JavaScripts have a native map method already), and through creating a mapAsync function where the work is done asynchronously rather than serially. The reason for this was so that we could avoid triggering the browser’s “script running a long time” warning and, also, more importantly, provide the user with a responsive UI. photo © 2007 sputnik ...

## JavaScript for C# developers: callbacks (part II)

Last time , we wrote a map method for arrays (which I had to call mapp , so that we didn’t clash with the native version present in many browsers). To use the map method, you have to provide a callback function that would be called for every element in the array. The first change I want to make today is to allow for missing elements in the array. In that case, the callback shouldn’t be called. Here’s the obvious way of implementing this change: Array.prototype.mapp = function (process...