TITLE: How does the divisibility graphs work?
QUESTION [54 upvotes]: I came across this graphic method for checking divisibility by $7$. 
$\hskip1.5in$ 

Write down a number $n$.
    Start at the small white node at the bottom
  of the graph. For each digit $d$ in $n$, follow $d$ black arrows in a
  succession, and as you move from one digit to the next, follow $1$
  white arrow.   
For example, if $n = 325$, follow $3$ black arrows, then
  $1$ white arrow, then $2$ black arrows, then $1$ white arrow, and
  finally $5$ black arrows.
If you end up back at the white node, $n$ is divisible by $7$.

This method indeed works, I was wondering why this work and how could we generate such graph for an  arbitrary integer $k$?

REPLY [24 votes]: I thought I would add a note to some of the answers above.
I have redrawn it with a different layout. It's nice because it shows the symmetry.
The black arrows, which correspond to $+1$ move round the edge. The purple arrows correspond to multiplying by $10$. The nodes are labeled with the remainder after division by 7.