MAKE A MEME View Large Image Collatz-graph-20-iterations.svg Graphviz with the help of this Python program <pre> This python script generates a graph that shows 20 levels of the Collatz Conjecture level 1 The root of the tree contains only 1 results This will hold the ...
View Original:Collatz-graph-20-iterations.svg (1152x1125)
Download: Original    Medium    Small Thumb
Courtesy of:commons.wikimedia.org More Like This
Keywords: Collatz-graph-20-iterations.svg Graphviz with the help of this Python program <pre> This python script generates a graph that shows 20 levels of the Collatz Conjecture level 1 The root of the tree contains only 1 results This will hold the relationships for the graph Loop 20 times for c in range 20 newlevel set This will be the set of numbers in the level above us for x in level We now loop through each number in our current level There will only sometimes be an odd multiple of 3 plus one above us When x-1 mod 3 is 0 x is an even number half the time So we check against x-4 mod 6 because we don't want to find evens odd x-1 /3 if not x-4 6 else 0 if odd > 1 We don't want 1 the root or 0 no odd found newlevel add odd Put this into the next level resultsodd x Add a relationship to the graph newlevel add x 2 ; There will always be an even number above us resultsx 2 x Add a relationship to the graph Finally advance to the next level level newlevel Technically 1 is odd so 1 3+1 4 If included though this tends to make 2 and 1 overlap on the graph which is ugly Uncomment to include this relationship results1 4; Now we write the graph out to a file in dot format so that graphviz can read it f open 'collatz dot' 'w' For aesthetic reasons we set 8 as the centre node instead of 1 f write 'digraph G \n size 16 16 ;\n root 8;\n splines true;\n' for x in results f write d -> d;\n x resultsx f write ' \n' f close print Generated d nodes len results </pre> en wikipedia Derlay CommonsHelper 2010-03-07 TerrorBite wikipedia en TerrorBite original upload log page en wikipedia Collatz-graph-20-iterations svg 2010-03-07 16 29 TerrorBite 1440×1406× 532396 bytes <nowiki>This is a graph generated in bottom-up fashion of the orbits of all numbers under the Collatz map with an orbit length of 20 or less Created with Graphviz with the help of this Python program This python sc</nowiki> Collatz conjecture
Terms of Use   Search of the Day