1. RE: Army Composition

I'm no good at math (read: really, really bad), so this may be totally 
wrong.  But I like the challenge and I'd like to see the correct code if 
mine isn't it.
[code]
--Rank over Population Problem
--By A. Cassidy Napoli

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

--Soldiers     no requirements
--Squad Leader commands 20 soldiers
--Lieutenant   commands 10 Squad Leaders
--Captain      commands 10 Lt.s
--General      commands 5  Captains
include get.e
integer population,soldier,leader,lieutenant,captain,general

population = prompt_number("Population Size: ", {})
soldier    = floor(population / 1)

leader     = floor(soldier / 20)
if remainder (leader,20) then leader += 1 end if

lieutenant = floor(leader / 10)
if remainder (lieutenant,10) then lieutenant += 1 end if

captain    = floor(lieutenant / 10)
if remainder (captain,10) then captain += 1 end if

general    = floor(captain / 5)
if remainder (general,5) then general += 1 end if

puts(1, "Population: ")
? (population)

puts(1, "Soldiers: ")
? (soldier)

puts(1, "Squad Leaders: ")
? (leader)

puts(1, "Lieutenants: ")
? (lieutenant)

puts(1, "Captains: ")
? (captain)

puts(1, "Generals: ")
? (general)
[end code]



C. K. Lester wrote:
> I want to know how many a certain population can support.
> 
> If I have 2 million people, how many will be soldiers, how many 
> Generals,
> and how many of each rank in between... You have to build it from the 
> bottom
> up... Maybe there won't be any generals if the population isn't over a
> certain number...
> 
> Don't let the military designations confuse things. This isn't strictly 
> a
> military problem as much as it is a tiered-organization problem.
> 
> Thanks!
> ck
> 
> ----- Original Message -----
> From: <euman at bellsouth.net>
> To: "EUforum" <EUforum at topica.com>
> Sent: Wednesday, October 10, 2001 1:35 PM
> Subject: Re: Army Composition
> 
> 
> > First, how many Generals are there per people in the population?
> >
> > Euman
> > euman at bellsouth.net
> >
> > ----- Original Message -----
> > From: "C. K. Lester" <cklester at yahoo.com>
> > To: "EUforum" <EUforum at topica.com>
> > Sent: Wednesday, October 10, 2001 11:46
> > Subject: Army Composition
> >
> >
> > > 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?
> > >
> > > Thanks!
> > > ck
> 
>

new topic     » topic index » view message » categorize

2. RE: Army Composition

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 message » categorize

3. RE: Army Composition

Hmmm...Seems needlessly complicated.  Does this meet the reqirements?
[code]
--Rank over Population Problem
--By A. Cassidy Napoli

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

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

--Another way to look at it is like this:
--For every 20 soldiers there will be 1 Squad Leader
--For every 10 Squad Leaders there will be 1 lieutenant
--For every 10 Lieutenants there will be 1 captain
--For every 5 captains there will be 1 general

include get.e
integer totalpop,soldier,leader,lieutenant,captain,general

soldier = 0
leader = 0
lieutenant = 0
captain = 0
general = 0
totalpop   = prompt_number("Population Size: ", {})

for i = 1 to totalpop do
	if i>20 and not remainder (i,20) then --1 leader for every 20 soldiers
		leader +=1
		if not remainder (i,200) then --1 lieutenant for every 10 leaders or 
every 200 soldiers
			lieutenant += 1
			if not remainder(i,2000) then --1 captain for every 10 lieutenants or 
every 2000 soldiers
				captain+=1
				if not remainder(i,10000) then --1 general for every 5 captains or 
every 10000 soldiers
					general += 1
				end if
			end if
		end if
	end if
	
end for

soldier = totalpop-leader-lieutenant-captain-general
puts(1,"\n")
puts(1, "Population: ")
? (totalpop)

puts(1, "Soldiers: ")
? (soldier)

puts(1, "Squad Leaders: ")
? (leader)

puts(1, "Lieutenants: ")
? (lieutenant)

puts(1, "Captains: ")
? (captain)

puts(1, "Generals: ")
? (general)
[/code]

Matthew Lewis wrote:
> 
> 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
<snip>

new topic     » goto parent     » topic index » view message » categorize

4. RE: Army Composition

--0-1305699159-1002746784=:25980

Sorry, I messed up the formatting using Topica's web
interface.  Here's an attachment of the code I think works.

=====

new topic     » goto parent     » topic index » view message » categorize

5. RE: Army Composition

Okay, Dan, I've made a few modifications to your code. Let me know what I
need to do to resolve the questions I've peppered therein... :)

--<code begins>
include get.e
include misc.e

function product( sequence x )
atom prod
prod = x[1]
	for t=2 to length(x) do
		prod = prod * x[t]
	end for
	return prod
end function

integer s, sql,lt,cp,gn, p, total, matrixLeg
sequence matrix, ranks

-- I eventually want to be able to determine at
-- run time the number of different "levels" of rank.
-- For instance, I'd like to run stats on 4 levels
-- and 6 levels of rank for a given population.
-- So, instead of s, sql, lt, cp, and gn, I'll have
-- Level[1], Level[2], Level[3],..., Level[n]

ranks = { "Soldier" , "Leader" , "Captain" , "Sergeant" , "General" }
matrix = { 1, 20 , 10 , 10 , 5 }

if length(ranks) != length(matrix) then
	puts(1,"ERROR! Length of ranks does not equal length of matrix.\n")
	abort(0)
end if

matrixLeg = product( matrix )

while 1 do
p = prompt_number("enter the population of soldiers (0=quit): " ,
{0,1073741823} )

if p=0 then exit end if

 s = floor(matrixLeg*p/10556) -- how is 10556 calculated?
 sql = floor(s/matrix[2])
 lt = floor(sql/matrix[3])
 cp = floor(lt/matrix[4])
 gn = floor(cp/matrix[5])

total = s+sql+lt+cp+gn
s = s + (p-total)

puts(1, "matrixLeg: " & sprint(matrixLeg) & "\n")
puts(1, "population: " & sprint(p) & "\n")
puts(1, ranks[1]&"(s): " & sprint(s) & "\n")
puts(1, ranks[2]&"(s): " & sprint(sql) & "\n")
puts(1, ranks[3]&"(s): " & sprint(lt) & "\n")
puts(1, ranks[4]&"(s): " & sprint(cp) & "\n")
puts(1, ranks[5]&"(s): " & sprint(gn) & "\n")
puts(1, "total: " & sprint( s + sql + lt + cp + gn) & "\n")

end while

--<code ends>

new topic     » goto parent     » topic index » view message » categorize

6. RE: Army Composition

Hey, Dan, thanks for the help. All truth will soon be revealed.

> The number "10556" was  calculated by simple algebra:
>
> --Soldiers - no requirements
> --Squad Leader - commands 20 soldiers
> --Lt. - commands 10 Squad Leaders
> --Captain - commands 10 Lt.s
> --General - commands 5 Captains
>
>
> -- soldiers + squad leaders + Lts. + Captains + Generals = Population
> (army!)
> --s + (s/20) + ((s/20)/10) + (((s/20)/10)/10 ) + ((((s/20)/10)/10)/5)= P
> -- s + s/20  +  s/200 +  s/2000  + s/10000 = p
> -- 10000s + 500s + 50s + 5s + s = 10000p
> -- 10556s = 10000p
> -- s = 1000p/10556
>
>
> I don't understand what you mean by "4 levels and 6 levels" of rank.  You
> only specified 5 levels of rank.

Right. But "What If" I needed to calculate for a differently leveled
organization? What if my calculations required a 4-tier organization or a
6-tier organization, other than the 5-tier organization we've hard coded so
far...?

What if we had { "Soldier" , "Leader" , "Captain" , "General" }?

> If you want to find out how many different ranks there are, just look at
> each rank var, if not zero, increment a "NumberOfRanks" counter.

Yeah. That's what I mean. But how to implement? That's what I need to know.

> I didn't really understand what you're doing with the matrix, either, and
> the change in your rank system,
> ranks = { "Soldier" , "Leader" , "Captain" , "Sergeant" , "General" }
> seems wrong, it should be:
> ranks = { "Soldier" , "Leader" , "Sergeant" ,"Captain"  , "General" }

Okay! Sounds right to me. But anything would.

I'm just using familiar labels. We could also be using

	{ "Pion" , "Assistant Manager" , "Manager" , "VP" , "President" }

or something similar. The labels aren't what's important... It's the tiered
organization that matters.

Hopefully I've shed a little light on the above.

-ck

new topic     » goto parent     » topic index » view message » categorize

7. RE: Army Composition

C. K. Lester wrote:
> 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?

Here is my humble attempt. But first a few assumptions need to be 
stated. 

There is a precedence involved, such that we must have at least one of 
each rank, except if there are not enough people to fill all stations. 
Using the ranks above, if there was only an army of 4, then we would 
have a General, a Captain, a Lt, and a Squad leader, but no grunts.

So, each SL can handle 20 grunts plus him/herself thus a maximum of 21 
people are involved for each SL. A Lt can handle 10 SL plus him/herself, 
thus as there as 21 people for each SL it means that for a Lt there is a 
maximum of 10 * 21 + 1 = 211. And so on up the line. This means that a 
General can have as many as 10556 people under him/herself.

So for every 10556 people (or fraction thereof) we need a General. 
Taking the Generals out of the remaining corp size, we can then see how 
many Captains are needed for the remaining people. Etc...

Anyhow, here is a generalised program that does all these calcs...

-------------
sequence UnitHead,      -- Rank of unit leader
         MaxUnitSize,   -- Maximum number of immediate subordinates
         MaxGroupSize,  -- Maximum number of total subordinates
         UnitSize       -- Number of people in each rank
         
integer CorpSize        -- Total size of army corp
                                                  
        
UnitHead = {
        "General",
        "Captain",
        "Lieutenant",
        "Corporal",
        "Soldier"
        }                 
MaxUnitSize = { 5, 10, 10, 20, 0 }

CorpSize = 20000
            
-- Returns the next integer if the parameter has a decimal portion.
function ceiling(atom x)
    integer q
    
    q = floor(x)
    return q + (x!=q)
end function

-- Calculates the total number of subordinates for each rank.    
procedure CalcGroupSize()
    integer lStart
    
    lStart = 0
    MaxGroupSize = repeat(0, length(UnitHead))
    
    for i = length(UnitHead) to 1 by -1 do
        MaxGroupSize[i] = MaxUnitSize[i] * lStart + 1
        lStart = MaxGroupSize[i]
    end for
end procedure
  

-- Calculates the required number of people for each rank.
procedure CalcUnitSize()
    integer lRemaining
    
    lRemaining = CorpSize
    UnitSize = repeat(0, length(UnitHead))
                         
    for i = 1 to length(UnitHead) do    
        UnitSize[i] = ceiling(lRemaining / MaxGroupSize[i])
        lRemaining -= UnitSize[i]
    end for
    
end procedure
    
procedure DoCalcs()

    CalcGroupSize()
    
    CalcUnitSize()
    
end procedure

              
DoCalcs()
       
printf(1, "With a total Corp size of %d, we get ...\n", CorpSize)
for i = 1 to length(UnitHead) do
    printf(1, " %-20s: %d\n", {UnitHead[i], UnitSize[i]})
end for        
-------------
Derek.

new topic     » goto parent     » topic index » view message » categorize

8. RE: Army Composition

This doesn't take into account variable tiers, but it seems to work 
quite well for the given problem..

Chris

This code sorts a given population into ranks, from bottom up.
IE. there must be more than 20 people to have a sergeant.

< CODE >
constant Population=rand(1000000)

atom Pop,Gen,Cpt,Lt,Sgt,Prv
integer P_inc,S_inc,L_inc,C_inc
Pop=Population
Gen=0    Cpt=0    Lt=0    Sgt=0  Prv=0
P_inc=0  S_inc=0  L_inc=0  C_inc=0

while Pop do
   Pop -=1  Prv+=1   P_inc+=1
   if Pop and P_inc=20 then -- Sargeant
      Pop -=1     Sgt+=1   S_inc+=1
      P_inc=0
      if Pop and S_inc=10 then -- Lieutenants
         Pop -=1     Lt+=1       L_inc+=1
         S_inc=0
         if Pop and L_inc=10 then -- Captains
            Pop -=1     Cpt +=1     C_inc +=1
            L_inc=0
            if Pop and C_inc =5 then -- Generals
               Pop -=1   Gen +=1
               C_inc=0
            end if
         end if
      end if
   end if
end while

puts(1,sprintf("Total Population: %d\n" &
               "-------------------------------\n" &
               "\n" &
               "Rank Distribution:\n" &
               "----------------------\n" &
               "  Generals      : %d\n" &
               "  Captains      : %d\n" &
               "  Leiutenants   : %d\n" &
               "  Sargeants     : %d\n" &
               "  Privates      : %d\n",
               {Population,Gen,Cpt,Lt,Sgt,Prv}))

while get_key()=-1 do end while

< END CODE >

new topic     » goto parent     » topic index » view message » categorize

9. RE: Army Composition

> C.K.,
> 
> Would this be a "real-time" recalc of number of tiers?
> 
> That is, in either the beginning or course of use of your program, would
> there be a query (or other opportunity to set):  "how many tiers 
> of managers
> do you want?"

Yes.

new topic     » goto parent     » topic index » view message » categorize

10. RE: Army Composition

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


>I had to modify your program for a few typos... and I made a few other
>aesthetic changes. HOWEVER, it doesn't work properly... Check this out:

That's what I get for coding in an email.  I made some changes.  Here's what
I came up with:

include get.e

sequence required, amount, actual, ranks
atom pop, startpop
object junk

pop = rand(1000000)

pop = 20000 -- for testing purposes
startpop = pop

required = {1,20,10,10,5}
ranks = { "Soldier", "Squad Leader","Lieutenant","Captain","General" }

amount = repeat(1,length(required))
actual = repeat(0,length(required))
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
for i = length(required) to 1 by -1 do
    for j = 2 to i do
      sum = product( required[j..i] )
      amount[i] += sum
    end for
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
    pop -= 1
    -- account for overflow
  end if
  quo = floor( pop / amount[ix] )
  sum = quo
  actual[ix] += sum
  pop -= sum
  for i = ix-1 to 1 by -1 do
    sum *= required[i+1]
    pop -= sum
    actual[i] += sum
  end for
  --pop = remainder( pop , amount[ix] )
  ix -= 1
end while

printf(1,"\nFor a population of %d\n\n",startpop)

for t=1 to length(actual) do
 printf(1,"%15s\t%5d\n",{ranks[t],actual[t]})
end for

pop = 0
for i = 1 to length(actual) do
    pop += actual[i]
end for

printf(1,"%21d\n",pop)


junk = wait_key()

new topic     » goto parent     » topic index » view message » categorize

Search



Quick Links

User menu

Not signed in.

Misc Menu