Solution (source code)

= Solution

Write the sets as $A_1,A_2,\ldots$, and list each nonempty countable set as $A_i=\{a_{i1},a_{i2},\ldots\}$. Enumerate the pairs $(i,j)\in\mathbb N^2$ along successive diagonals, as in the <Cantor pairing function>, and output $a_{ij}$ when it has not appeared before. Every member of $\bigcup_iA_i$ eventually appears, proving that a <countable union of countable sets> is countable.