FFRANK has asked for the wisdom of the Perl Monks concerning the following question:

Update: simplified...

Dear Monks,

For indexing the best values out of a fractal structure built by adding iteratively +1 to the diagonal 4 of a 4X4 square.

Output indices for $level = $max, $level = $max-1, $level = $max -2 untill some condition has been met. In my environment, this condition will be met at level 0, or 1 or 2 in most cases, so checking the indice for low levels without building too much may be faster.

When it gets to depth 8 and more, it is very long to run (hours).

I have a good feeling for nested loops, I was also thinking about PDL, which is supposed to be better to handle large data sets... I have been working this out line by line because storing those structures as is was taking way too much memory.

Thank you very much for your comments, regards.

Frank

Replies are listed 'Best First'.
Re: Fractal structure index puzzle
by lin0 (Curate) on Jul 18, 2007 at 18:29 UTC

    Hi FFRANK,

    you might want to have a look to a recent article in the Free Software Magazine on Generating Cool Fractals. There, you would find a Benchmark showing execution time for computing a Mandelbrot fractal image using different languages. It took about 200 seconds with gcc and g77 for 2000 points and 1000 iterations. For the same image using PDL, it took about 650 seconds. If you main concern is execution time, then I would think about using C. If you definitely want to do it in Perl, then PDL is your best bet. However, you would have to learn how to use matrix operations to avoid the use of loops as much as you can.

    Good luck!

    lin0
Re: Fractal structure index puzzle
by BrowserUk (Patriarch) on Jul 19, 2007 at 03:24 UTC

    Should the top left (20x20) block (of 64x64) at depth 3 look like this:

    3 2 2 2 1 0 0 0 1 0 0 0 1 0 0 0 2 1 1 1 ... 2 3 2 2 0 1 0 0 0 1 0 0 0 1 0 0 1 2 1 1 ... 2 2 3 2 0 0 1 0 0 0 1 0 0 0 1 0 1 1 2 1 ... 2 2 2 3 0 0 0 1 0 0 0 1 0 0 0 1 1 1 1 2 ... 1 0 0 0 3 2 2 2 1 0 0 0 1 0 0 0 1 0 0 0 ... 0 1 0 0 2 3 2 2 0 1 0 0 0 1 0 0 0 1 0 0 ... 0 0 1 0 2 2 3 2 0 0 1 0 0 0 1 0 0 0 1 0 ... 0 0 0 1 2 2 2 3 0 0 0 1 0 0 0 1 0 0 0 1 ... 1 0 0 0 1 0 0 0 3 2 2 2 1 0 0 0 1 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2 1 1 1 3 2 2 2 1 0 0 0 ... 1 2 1 1 1 2 1 1 1 2 1 1 2 3 2 2 0 1 0 0 ... 1 1 2 1 1 1 2 1 1 1 2 1 2 2 3 2 0 0 1 0 ... 1 1 1 2 1 1 1 2 1 1 1 2 2 2 2 3 0 0 0 1 ... 2 1 1 1 1 0 0 0 1 0 0 0 1 0 0 0 3 2 2 2 ... 1 2 1 1 0 1 0 0 0 1 0 0 0 1 0 0 2 3 2 2 ... 1 1 2 1 0 0 1 0 0 0 1 0 0 0 1 0 2 2 3 2 ... 1 1 1 2 0 0 0 1 0 0 0 1 0 0 0 1 2 2 2 3 ... ...

    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    "Science is about questioning the status quo. Questioning authority".
    In the absence of evidence, opinion is indistinguishable from prejudice.
      The leftmost 20x20 corner at depth 3 should look like this (second one):
      3 2 2 2 2 1 1 1 2 1 1 1 2 1 1 1 2 1 1 1
      2 3 2 2 1 2 1 1 1 2 1 1 1 2 1 1 1 2 1 1
      2 2 3 2 1 1 2 1 1 1 2 1 1 1 2 1 1 1 2 1
      2 2 2 3 1 1 1 2 1 1 1 2 1 1 1 2 1 1 1 2
      2 1 1 1 3 2 2 2 2 1 1 1 2 1 1 1 1 0 0 0
      1 2 1 1 2 3 2 2 1 2 1 1 1 2 1 1 0 1 0 0
      1 1 2 1 2 2 3 2 1 1 2 1 1 1 2 1 0 0 1 0
      1 1 1 2 2 2 2 3 1 1 1 2 1 1 1 2 0 0 0 1
      2 1 1 1 2 1 1 1 3 2 2 2 2 1 1 1 1 0 0 0
      1 2 1 1 1 2 1 1 2 3 2 2 1 2 1 1 0 1 0 0
      1 1 2 1 1 1 2 1 2 2 3 2 1 1 2 1 0 0 1 0
      1 1 1 2 1 1 1 2 2 2 2 3 1 1 1 2 0 0 0 1
      2 1 1 1 2 1 1 1 2 1 1 1 3 2 2 2 1 0 0 0
      1 2 1 1 1 2 1 1 1 2 1 1 2 3 2 2 0 1 0 0
      1 1 2 1 1 1 2 1 1 1 2 1 2 2 3 2 0 0 1 0
      1 1 1 2 1 1 1 2 1 1 1 2 2 2 2 3 0 0 0 1
      2 1 1 1 1 0 0 0 1 0 0 0 1 0 0 0 3 2 2 2
      1 2 1 1 0 1 0 0 0 1 0 0 0 1 0 0 2 3 2 2
      1 1 2 1 0 0 1 0 0 0 1 0 0 0 1 0 2 2 3 2
      1 1 1 2 0 0 0 1 0 0 0 1 0 0 0 1 2 2 2 3

      Frank