Last active
January 20, 2016 16:12
-
-
Save mapio/c44c029a1c1a5ff1ab59 to your computer and use it in GitHub Desktop.
The Hasse diagram of the divisibility graph
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def divisibility_graph( n ): | |
E = set() | |
for dst in range( 30 ): | |
for src in range( 2, dst ): | |
if dst % src == 0: | |
E.add( ( src, dst ) ) | |
return E | |
def hasse_diagram( E ): | |
E2 = set() | |
for e0 in E: | |
for e1 in E: | |
if e0[1] == e1[0]: | |
E2.add( ( e0[0], e1[1] ) ) | |
return E - E2 | |
def to_dot( E ): | |
res = [ 'digraph G { rankdir = LR; ' ] | |
res.extend( [ '{}->{};'.format( *e ) for e in E ] ) | |
res.append( '}' ) | |
return '\n'.join( res ) | |
if __name__ == '__main__': | |
from sys import argv | |
E = divisibility_graph( int( argv[ 1 ] ) ) | |
H = hasse_diagram( E ) | |
print to_dot( H ) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This code generates the Hasse diagram of the divisibility graph in Graphviz format. You can run it as