James
James

Reputation: 262

Selecting multi dimentional array

I have a project where I am dynamically creating a report. The number of columns may change, so I have figured out a table to help me determine which paper size to use. The size of fonts across and page sizes down. The intersecting numbers are numbers of columns. I would like to choose the combination with the largest font size and the smallest paper size. Is there an easy method to determining this combination? Any help is always appreciated.

EDIT
Here is a copy of the table.

enter image description here

I have been racking my brain trying to come up with a solution, but I don't even know where to start. When the report is created the exact number of columns may be different than what is listed in the table, but I want to select the next larger number listed in the table.

Upvotes: 0

Views: 45

Answers (2)

James
James

Reputation: 262

I came up with the following solution, but I am wondering whether there is a more efficient method of doing the same thing.

enter image description here

I reversed the order of the fonts, shown above, and used the following code.

// Example number of columns  
$NumColumns = 15;
//

$PageFont[0][0] = 7;
$PageFont[0][1] = 8;
$PageFont[0][2] = 8;
$PageFont[0][3] = 9;
$PageFont[1][0] = 10;
$PageFont[1][1] = 11;
$PageFont[1][2] = 12;
$PageFont[1][3] = 13;
$PageFont[2][0] = 13;
$PageFont[2][1] = 14;
$PageFont[2][2] = 15;
$PageFont[2][3] = 16;
$PageFont[3][0] = 16;
$PageFont[3][1] = 17;
$PageFont[3][2] = 19;
$PageFont[3][3] = 20;

$Font = NULL;
$Page = NULL;

// $x = Page Size
// $y = Font Size

for($x=0;$x<4;++$x) {
    for($y=0;$y<4;++$y) {
        if($PageFont[$x][$y] >= $NumColumns) {
            $Page = $x;
            $Font = $y;
            break;
        }
    }
}

Upvotes: 0

Harry Mustoe-Playfair
Harry Mustoe-Playfair

Reputation: 1419

This is a multivariate problem with multiple solutions. It can be clearly seen that there is no unique solution for some numbers of columns (e.g. 13, 16).

As such, it depends which you value more - the larger font sizes or the smaller paper sizes.

I.e. it is unclear what your goal variable is.

You could create some sort of index or score to a combination based on:

  1. readability (in this case based on font size)
  2. paper saving

So, as an example

  1. a font size of 8pt would have a readability of 0 (minimal) while a font size of 11pt would have a readability score of 100 (maximal)
  2. a paper size of 8.5x11 would have a paper saving score of 100 (minimal) while a paper size of 17x11 would have a score of 0 (maximal)

You can then combine these scores in some way to produce a result.

How you combine those scores is then down to what you value most. Let p be paper saving and r be readability, you could have:

y = 5p + 2x

This would value paper saving over readability at a ratio of 2/5, or you could have:

y = e^p + e^x

So that they're both equally weighted, but exponentially, meaning a big font on big paper is better than a medium font on medium paper.

Once you have determined what the combination is with the lowest score that can satisfy your minimum needs, then you can choose the correct combination.

Upvotes: 1

Related Questions