My solution to the XKCD Puzzle
So here’s how I’ve been thinking about that XKCD puzzle. My approach is essentially an exercise in the techniques covered in John Baez’ Quantum Gravity seminar for 2003-2004.
Basically, we consider each possible path from the source — which we’ll assume is at the origin of our lattice — to the target — which will be at lattice coordinates — as a series circuit, and the collection of all possible paths is a giant parallel circuit. If a given path has length
it passes through
resistors, and so its total resistance is
. Thus we need to form the sum over all paths
and take the reciprocal of this sum. So we’ve got a combinatorial problem: how many lattice paths have length
and go from the origin to
? Let’s call this number
and build the “exponential generating function”
We choose the exponential generating function here rather than the ordinary generating function because of a manipulation we want to do later that looks nicer for exponential generating functions. We’ll go from
to our desired sum a little later.
For now, let’s consider a simpler generating function. Consider the number of paths on a one-dimensional lattice with length
that start at
and end at
. First off, if
we have no paths that work. Similarly, if
is not divisible by
we won’t have any good paths. But when
, there are generally many different paths. How do we get our hands on one? Choose
steps to take left and the other
to take right, and we’ll end up
steps to the right. So we set
to get the exponential generating function
where is a Bessel function of the first kind.
Now a path in the two-dimensional lattice is really a mixture of two one-dimensional paths. That is, we break our steps up into chunks of
and
steps, respectively, put a one-dimensional path on the
chunk ending at
, and put a one-dimensional path on the
chunk ending at
. And it turns out that generating functions are perfect for handling this!
This tells us how to find the number of paths of length
that end at
— it’s just the
th derivative of this power series, evaluated at
. That is
Now let’s consider the ordinary generating function for :
Here the coefficient of is the number of paths of length
(and thus with resistance
) from the origin to
. What we want to calculate is the sum
. To get at this, we’ll divide our power series by
and then integrate with respect to
. This will give the series
, which we can then evaluate at
. Notice that we never have any paths of length zero unless we’re counting up the reciprocal resistance from the origin to itself, which should definitely be infinite anyway, so dividing by
isn’t really a problem.
Now I admit there’s one glaring problem here: I don’t know offhand how to go from an exponential generating function to an ordinary generating function, much less how to integrate what we get from doing that to this product of Bessel functions.
Any thoughts?
[UPDATE]: I was just working on some numerics and there’s a problem here somewhere. The coefficients are off, but by a (sort of) predictable amount. I don’t really have time to fix this now, so I’ll come back with more later.
[UPDATE]: Okay, I see what’s wrong now. I’m adjusting what I said above.
[UPDATE]: Someone pointed out to me that after all of this I need to do a renormalization just like for the path integrals in quantum field theory. That is, in the above I need to restrict to paths that never hit the same edge twice, which is a harder combinatorial problem than I expected.
Still, it’s nifty to see the Bessel functions…

I don’t think it’s quite so complicated; I seem to recall seeing a solution to a very similar problem (the locations on the grid were different, but everything else was the same) that was only a couple lines. Unfortunately I have no idea where I saw it.
I’ve also seen simple solutions, but usually they’re for only one choice of terminal point, and I’m not quite sure I buy them. It doesn’t help that I’ve seen multiple “simple” solutions.
One in particular for the resistance across a single resistor claims to get 1/2 an ohm in two different ways. The first involves some hand-waving about impedance that I’m not sure I trust, and the second seems to completely neglect all the other closed paths that get back around from one point to the other. And this is among the clearest expositions I could find.
Basically, to whatever extent one or another special case I’ve seen turns out to be right, there seems to be almost no concept of “what’s really” going on here, which leads to a true understanding of not only the special case, but of the problem as a whole. My solution, on the other hand, recognizes the basic idea as thinking of the whole grid as a massively parallel circuit, and the calculation to actually be a discretized path-integral. At each step (modulo an error I’m about to fix) it’s clear what we’re counting or adding up, and what relation that part has to the whole. The only problem is that I don’t yet know how to extract an answer from the framework.
See http://aps.arxiv.org/abs/cond-mat/9909120 for solutions in terms of lattice Green functions for various lattices. For this particular problem the answer would be 4/pi-1/2.
This isn’t particularly useful for the problem, but it’s a nice little thing I found while I was working on it.
When a+b has the same parity as n, G_{a,b,n} is just (n choose (a+b+n)/2) (n choose (a-b+n)/2). (Otherwise, it’s zero, of course.)
This is because you need to choose exactly (a+b+n)/2 steps in the path to go either up or right, and exactly (a-b+n)/2 steps to go either down or right.