3 ms·
I wrote a post on reddit with some code to generate diagrams with generalized divisibility testing the last time I saw this idea (about two years ago): https://
by Figs 11y ago
I wrote a post on reddit with some code to generate diagrams with generalized divisibility testing the last time I saw this idea (about two years ago): https://www.reddit.com/r/math/comments/1p9g8t/start_at_the_bottom_pick_any_number_take_the/cd095x4 https://www.reddit.com/r/math/comments/1p9g8t/start_at_the_b...
Copied here for the lazy:
I wrote a small python script to generate DOT code for graphviz so that you can just input the base and the number to check division and automatically draw the graph. (The resulting graphs aren't as pretty as one made by a human, but it's kind of fun to poke around with it.)
Here's the script:
base = 10
divby = 7
print "digraph {"
print " 0 [shape=doublecircle]"
for i in xrange(0, divby):
print " ", i, "->", (i+1)%divby
print " ", i, "->", (base*i)%divby, "[arrowhead=empty]"
print "}"
Save it to a file such as `make_graph.py`. Then, as long as you have the graphviz binaries on path, you can render an image like:
python make_graph.py > graph.dot
dot -Tpng graph.dot -o out.png
Here are some sample outputs:
- [base = 3, divby = 11](http://imgur.com/cwUmnME http://imgur.com/cwUmnME)
- [base = 10, divby = 7](http://imgur.com/O7GYw17 http://imgur.com/O7GYw17)
- [base = 10, divby = 10](http://imgur.com/k6xC0CQ http://imgur.com/k6xC0CQ)
- [base = 10, divby = 11](http://imgur.com/1SSXKcK http://imgur.com/1SSXKcK)
- [base = 16, divby = 7](http://imgur.com/QZzSyva http://imgur.com/QZzSyva)
Not all the edges are actually reachable -- e.g. base 10, divby 10 has a black edge from 9 to 0 even though you can't ever wrap around to 0 since `(10 * anything)%10` is zero -- so the biggest you can get to is 9, then when you follow the white edge for 9x you start over at zero... There may also be other edge cases I haven't thought of ;)