in reply to Ceiling elements of an array!
I think the problem is confusion over the term 'ceiling'. I believe the desire is to divide n modules into two (nearly) equal groups. If n is odd, obviously, one group will be larger.
use strict; use warnings; use POSIX qw(ceil); my $modules = shift; my $first_group = ceil($modules/2);0 printf "Call %d on port 80, %d on port 8080\n",$first_group,$modules - + $first_group;
$: perl divide.pl 8 Call 4 on port 80, 4 on port 8080 $: perl divide.pl 9 Call 5 on port 80, 4 on port 8080 $:
Vaguely related to Distribute the leftovers.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Ceiling elements of an array!
by marinersk (Priest) on May 06, 2015 at 18:00 UTC | |
by AnomalousMonk (Archbishop) on May 06, 2015 at 22:48 UTC | |
by GotToBTru (Prior) on May 06, 2015 at 18:13 UTC |