RE: Army Composition

new topic     » goto parent     » topic index » view thread      » older message » newer message

Here's how I'd solve this:

You need to know the total number of people, which means you need to know
the soldiers (p), squad leaders (s), lt's (l), captains (c) and generals
(g).

It's almost like a factorial.  First calclulate the soldiers that one
general would have under him:

5 * 10 * 10 * 20 = 10,000

Next, the squad leaders:
5 * 10 * 10 = 500

Lt:
5 * 10 = 50

Captain:
5

Plus one for the general gives you 10,556.

I'm not sure how you want to deal with remainders, but you can either
'overburden' one commander with more than these levels, or have one with
just a fraction of the amount laid out.

I'd do the same calculations for the lower ranks, and start subtracting:

g = 10,556
c = 2,221
l = 211
s = 21

I'd keep these values in a sequence, and here'd be the code:

sequence required, amount, actual
atom pop

pop = rand(1000000)
required = {1,20,10,10,20,5}
amount = repeat(0,length(required))
actual = amount

function product( sequence mult )
  atom p
  p = 1
  for i = 1 to length( mult ) do
    p *= mult[i]
  end for
  return p
end function

-- first calculate required number for each rank
atom sum
for i = length(required) to 1 by -1 do
  sum = product( required[1..i] )
  amount[i..length(required)] += sum
end for

atom quo
integer ix
ix = length( actual )
-- next calculate amount of each for a population
while ix and pop do
  if ix < length( actual ) then
    actual[ix+1] += 1
    -- account for overflow
  end if
  quo = floor( pop / amount[ix] )
  sum = quo
  for i = ix to 1 by -1
    sum *= amount[i]
    actual[i] += sum
  end for
  pop = remainder( pop / amount[i] )
  ix -= 1
end while

? actual


Unfortunately, I can't test this right now, but it should calculate for an
arbitrary number of ranks (just change the initial sequences) with whatever
requirements you're looking for.

Matt Lewis


-----Original Message-----
From: C. K. Lester [mailto:cklester at yahoo.com]

For a given population, what is the maximum number of persons at each rank?

Soldiers - no requirements
Squad Leader - commands 20 soldiers
Lt. - commands 10 Squad Leaders
Captain - commands 10 Lt.s
General - commands 5 Captains

I need a EUPHORIA program to compute these values given a population.

Who's got one?

new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu