Neither did I, I was just curious about your "This one loops over the list of items once (at most)." claim. Knowing mine makes several passes, I wondered how they compared. I (think) I see that you actually do make 2 passes: 1 to determine the no. of columns; 1 to do the formatting.

I'm not sure what you mean by the 2N^.5 bit? No matter how I bracket that, it always comes out to 74 compared to 37/2 = 18 or 19.

The problem with limiting the columns in that way is that you miss the edge case where the entire list will format into 1 row--and split it across 2.

The reason mine arrives at the answer quicker in all but the smallest widths case, is that I come at from the other end. I iterate the rows 1 .. N, and calculate the columns.

I noticed that in the general case increasing the number of rows until it fit arrived more quickly than increasing the number of columns as it considered less duplicate cases. For best performance, you could probably determine some formula that would indicate which end to start from, but my math ain't that strong.


Examine what is said, not who speaks.
"Efficiency is intelligent laziness." -David Dunham
"Think for yourself!" - Abigail
"Memory, processor, disk in that order on the hardware side. Algorithm, algorithm, algorithm on the code side." - tachyon

In reply to Re^4: 'ls -C' column style (sideways) by BrowserUk
in thread 'ls -C' column style by hv

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.