in reply to Re: Powers of three
in thread Powers of three

honestly i don't remember it was written in my statistics class at 9am
i'm also partially curious as to why the program works, i know what its doing, i worked it out by hand before writing it in perl

Replies are listed 'Best First'.
Re^3: Powers of three
by truedfx (Monk) on Feb 07, 2006 at 18:04 UTC
    A simple explanation of why it works, since you wondered:
    If you continue your triangle, you end up with this:
                   1
                  1 1
                 1 0 1
                1 1 1 1
               1 0 0 0 1
              1 1 0 0 1 1
             1 0 1 0 1 0 1
            1 1 1 1 1 1 1 1
           1 0 0 0 0 0 0 0 1
          1 1 0 0 0 0 0 0 1 1
         1 0 1 0 0 0 0 0 1 0 1
        1 1 1 1 0 0 0 0 1 1 1 1
       1 0 0 0 1 0 0 0 1 0 0 0 1
      1 1 0 0 1 1 0 0 1 1 0 0 1 1
     1 0 1 0 1 0 1 0 1 0 1 0 1 0 1
    1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
    
    You probably see a pattern by now, but if not, change all the 0s to spaces, and all the 1s to #s:
                   #
                  # #
                 #   #
                # # # #
               #       #
              # #     # #
             #   #   #   #
            # # # # # # # #
           #               #
          # #             # #
         #   #           #   #
        # # # #         # # # #
       #       #       #       #
      # #     # #     # #     # #
     #   #   #   #   #   #   #   #
    # # # # # # # # # # # # # # # #
    
    No matter how far down you go, you always end up with a triangle, and you can continue by copying that triangle to its bottom left and right sides. This is easy to see, but I can't find the words that actually explain it, so please take a look for yourself if you have doubts about that. Now take a look at this: the first row has 1 as its sum. This triangle-point is copied twice, so the first 2 * 1 rows have 3 * 1 as their sum. This triangle is copied twice, so the first 2 * 2 * 1 rows have 3 * 3 * 1 as their sum. The first 2^3 * 1 rows have 3^3 * 1 as their sum. I'm sure you get the idea by now :)
    It's not proof, but hopefully it's good enough.
Re^3: Powers of three
by tweetiepooh (Hermit) on Feb 10, 2006 at 11:09 UTC
    Nice code.

    Logically the state of any point is an XOR of its two parents taking a missing parent to be 0. (and seeding with a 1 at the point)