Results 1 to 11 of 11

Thread: Collatz Conjecture / Collatz Tree

  1. #1

    Thread Starter
    Hyperactive Member Arrow_Raider's Avatar
    Join Date
    Dec 2001
    Location
    AVR Lovers Club
    Posts
    423

    Collatz Conjecture / Collatz Tree

    I have made a WPF application that constructs a Collatz Tree for the collatz conjecture problem. The collatz conjecture is that any number will eventually reach and terminate at 1 by following these steps:
    If the number is even, divide the number by 2.
    If the number is odd, multiply the number by 3 and add 1.
    Repeat until number has reached 1.

    Here is an example starting with 3:
    3
    10 (3x3+1)
    5 (10/2)
    16 (5x3+1)
    8 (16/2)
    4 (8/2)
    2 (4/2)
    1 (2/1)

    The sequence starting with any number eventually reaches a 2^n number which is where it then begins to terminate.


    My program (optionally) starts with 1 and shows the paths to reach 1.
    Here is a screenshot:



    The red numbers are numbers that satisfy the following: (n - 1) mod 3 = 2. All numbers under a red number will not branch out both directions; each of the red nodes can only have 1 child.
    Last edited by Arrow_Raider; Feb 14th, 2009 at 09:22 PM.
    My monkey wearing the fedora points and laughs at you.

  2. #2
    KrisSiegel.com Kasracer's Avatar
    Join Date
    Jul 2003
    Location
    USA, Maryland
    Posts
    4,985

    Re: Collatz Conjecture / Collatz Tree

    Neat. Never heard of that stuff but a none-the-less
    KrisSiegel.com - My Personal Website with my blog and portfolio
    Don't Forget to Rate Posts!

    Free Icons: FamFamFam, VBCorner, VBAccelerator
    Useful Links: System.Security.SecureString Managed DPAPI Overview Part 1 Managed DPAPI Overview Part 2 MSDN, MSDN2, Comparing the Timer Classes

  3. #3
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    Re: Collatz Conjecture / Collatz Tree

    Nice. I've heard of Collatz before but it's obviously not as interesting as Happy Numbers. However, now that you've made a graph, you have upped the appeal of Collatz, giving Happy Numbers some real competition. Well done.

  4. #4
    type Woss is new Grumpy; wossname's Avatar
    Join Date
    Aug 2002
    Location
    #!/bin/bash
    Posts
    5,682

    Re: Collatz Conjecture / Collatz Tree

    The graph is upside down and I don't like the colour.

  5. #5
    MS SQL Powerposter szlamany's Avatar
    Join Date
    Mar 2004
    Location
    Connecticut
    Posts
    18,263

    Re: Collatz Conjecture / Collatz Tree

    7 was coming after 11 - wasn't it...

    It all makes sense now.

  6. #6
    MS SQL Powerposter szlamany's Avatar
    Join Date
    Mar 2004
    Location
    Connecticut
    Posts
    18,263

    Re: Collatz Conjecture / Collatz Tree

    9 and 14 as well - that's a curious spot - can you show the tree below that branch?

  7. #7

    Thread Starter
    Hyperactive Member Arrow_Raider's Avatar
    Join Date
    Dec 2001
    Location
    AVR Lovers Club
    Posts
    423

    Re: Collatz Conjecture / Collatz Tree

    I'll be releasing the source code soon, but I need to clean it up first.

    Here is the tree under node 11:
    Name:  collatz2.JPG
Views: 14792
Size:  69.5 KB


    This is the code I am using to generate the tree:
    Code:
    private BinaryTreeOfLong GenerateTree(int node, int n)
    {
    	if (n > 0)
    	{
    		BinaryTreeOfLong t = new BinaryTreeOfLong();
    		t.Value = node;
    		if ((node - 1) % 3 == 0)
    		{
    			if (((node - 1) / 3) % 2 == 1 && (node - 1) / 3 != 1)
    			{
    				t.LeftSubtree = GenerateTree((node - 1) / 3, n - 1);
    			}
    		}
    		else if ((node - 1) % 3 == 2)
    			t.Flag1 = true;
    		t.RightSubtree = GenerateTree(node * 2, n - 1);
    		return t;
    	}
    	else
    		return null;
    }
    Note: BinaryTreeOfLong is basically BinaryTree<long>. I don't know how to get xaml to work with generics, so I just did it like that. I'll figure out how to use generics in xaml eventually... but I was too lazy yesterday.
    Last edited by Arrow_Raider; Feb 15th, 2009 at 10:20 AM.
    My monkey wearing the fedora points and laughs at you.

  8. #8
    MS SQL Powerposter szlamany's Avatar
    Join Date
    Mar 2004
    Location
    Connecticut
    Posts
    18,263

    Re: Collatz Conjecture / Collatz Tree

    The "master numbers" behind 11 are remarkable...

    But that's a different discussion.

  9. #9

    Thread Starter
    Hyperactive Member Arrow_Raider's Avatar
    Join Date
    Dec 2001
    Location
    AVR Lovers Club
    Posts
    423

    Re: Collatz Conjecture / Collatz Tree

    Do master numbers rule over mendhak's happy numbers?
    My monkey wearing the fedora points and laughs at you.

  10. #10
    Frenzied Member MaximilianMayrhofer's Avatar
    Join Date
    Aug 2007
    Location
    IM IN YR LOOP
    Posts
    2,001

    Re: Collatz Conjecture / Collatz Tree

    Never.

  11. #11
    New Member
    Join Date
    Sep 2005
    Posts
    0

    Re: Collatz Conjecture / Collatz Tree

    Hi Arrow:

    Can you post the entire code for the Collatz Tree?

    Thanks.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width