#! /usr/bin/perl

use POSIX;

$column_count = 3;
$available_width = 100;

for ($column_gap = 10; $column_gap <= 90; $column_gap ++) {
    if ( (($column_count - 1) * $column_gap) < $available_width ) {
	$n = $column_count;
	$na = $column_count;
	$w = ($available_width - (($n - 1) * $column_gap))/$n;
	$wa = ($available_width - (($n - 1) * $column_gap))/$n;
#	print "(18) N := $column_count\n";
#	print "(19) W := ($available_width - (($n - 1) * $column_gap))/$n = $w \n";
    } elsif ( $column_gap >= $available_width ) {
	$n = 1;
	$na = 1;
	$w = $available_width;
	$wa = $available_width;
#	print "(21) N := $n\n";
#	print "(22) W := $available_width\n";
    } else {
	$n = floor($available_width / $column_gap);
	$na = floor($available_width / $column_gap) + 1;
	$w = ($available_width - (($n - 1) * $column_gap))/ $n;
	$wa = ($available_width - (($na - 1) * $column_gap))/ $na;
#	print "(24) N := floor($available_width / $column_gap) = $n;\n";
#	print "(25) W := ($available_width - (($n - 1) * $column_gap)) / $n = $w;\n";
    }
    print "column-gap: $column_gap; column-count: $column_count; width: $available_width; /* currently: $n columns -- revised $na columns */\n";
}
