Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Odd number of pigs in cages

Status
Not open for further replies.

jimoo

Programmer
Jun 2, 2003
1,111
US
A farmer asks you to build 4 changes to hold his 9 pigs and he wants to you put an odd number of pigs in each cage. Each cage must contain at least 1 pig. How can you do that?



Jim
 
Put 3 pigs in each of 3 cages, then put the 3 cages in a larger one.

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
[tt]
+--------------------------------------------+
| |
| +----------+ +----------+ +----------+ |
| | P1 P2 P3 | | P4 P5 P6 | | P7 P8 P9 | |
| +----------+ +----------+ +----------+ |
| |
+--------------------------------------------+
[/tt]

--------------
Good Luck
To get the most from your Tek-Tips experience, please read
FAQ181-2886
As a circle of light increases so does the circumference of darkness around it. - Albert Einstein
 
Oops - My apologies for not hiding my answer.


--------------
Good Luck
To get the most from your Tek-Tips experience, please read
FAQ181-2886
As a circle of light increases so does the circumference of darkness around it. - Albert Einstein
 
Of course there are many other answers too, all based on the same general idea.
At a trivial level, put all 9 pigs in a cage. Put that cage in a bigger cage. Put the bigger cage in an even bigger cage... etc.
 
ALl correct responses and as you can tell there is more than one cage nesting combinations. A good riddle for your kids or office know it all.

Jim
 
lionelhill said:
Of course there are many other answers too
Anyone want to take a stab at just how many? I can think of two meaningful questions concerning the arrangement of pigs and cages. I've included the number of solutions I've been able to find.

1. How many topologically distinct arrangements of the four cages are there?
3

2. How many total arrangements of pigs and cages are there?
55
 
Oops, I definitely missed some of the topologically different cage arrangements. I'll give this problem some more thought tomorrow. In the meantime, please feel free to improve on my answers.
 
As two odds sum to an even, you need to nest cages.

But you cannot nest two cages within a third, as then the number of pigs in the outer cage is even again. So the only solutions for the cage topology is to have 1 or 3 cages within the 4th.

If doing two nestings that means 3 cages need to be nested with only the innner one having pigs directly in it and a seperate 4th cage, tha last topoloy solution is three nestings, which means all cages nesting with the inner one containing pigs.

Bye, Olaf.



 
Olaf, I don't think your reasoning is 100% correct. Here is an updated list of possible cage topologies, with a sample solution for each topology. In my solutions I've used {} to denote cages and integers to represent the number of pigs inside each cage. I'm hopeful that this list of cage topologies is complete. Later I will work on compiling a complete list of solutions for each topology.

1. One small cage nested inside a second, larger cage. A third and fourth cage standing alone with no nesting.
Sample solution: {{3}}, {3}, {3}

2. Linear nesting. A small cage inside a medium cage inside a medium-large cage inside a large cage.
Sample solution: {{{{9}}}}

3. Three small cages all inside a large cage.
Sample solution: {{3}, {3}, {3}}

4. Two small cages inside a medium cage inside a large cage.
Sample solution: {{ {3}, {3}, 3 }}

5. A medium cage containing a smaller cage and a separate small cage all inside a large cage.
Sample solution: { {{1}, 2}, {3}, 3 }
 


also
[[3] [3]] [3]

[[3]] [3] [3]

Skip,
[sub]
[glasses]Just traded in my old subtlety...
for a NUANCE![tongue][/sub]
 
That configuration doesn't work, Skip. The large cage in the nest contains six pigs.
 
An addition to karluk's list (see 6)...
1. One small cage nested inside a second, larger cage. A third and fourth cage standing alone with no nesting.
Sample solution: {{3}}, {3}, {3}

2. Linear nesting. A small cage inside a medium cage inside a medium-large cage inside a large cage.
Sample solution: {{{{9}}}}

3. Three small cages all inside a large cage.
Sample solution: {{3}, {3}, {3}}

4. Two small cages inside a medium cage inside a large cage.
Sample solution: {{ {3}, {3}, 3 }}

5. A medium cage containing a smaller cage and a separate small cage all inside a large cage.
Sample solution: { {{1}, 2}, {3}, 3 }

6. Three standalone medium cages with a small cage inside one of them.
Sample solution: {3}, {3}, {2 {1}}

 
Sam, I don't see how your topology #6 differs from your topology #1. All you've done is move two pigs from the inner cage to the outer cage in the nest
 
Yes, the cage arrangement is the same, but the pig placement is distinctly different. And it still meets the requirements.

Topologies 1 through 5 were copied from your post. This is how 1 and 6 differ...

1. {3}, {3}, {{3}}

6. {3}, {3}, {{1}2}

The way I read it, the solution depends on both cage topology and pig placement. The difference in pig placement gives separate solutions.

This solitary confinement solution might be needed if one of the pigs is antisocial and just doesn't get along with the other pigs. [bigsmile]


 
In my view your #6 should be included in the complete list of solutions for topology #1 rather than being listed separately. It's really not a new cage topology. Instead it is part of the answer to the second question I posed yesterday - How many total arrangements of pigs and cages are there? I'll try to work on that question over the weekend and see how many different ways the pigs can be moved around between cages.
 
Hmmm, that opens up a can of worms. Would these then be considered other valid solutions?

{ {1} {1} {7} }
{ {1} {3} {5} }
{ {1} {1} {1} 6 }
{1} {1} {6 {1}}
{1} {3} {4 {1}}
{1} {3} {2 {3}}

There are multiple possible pig placements for each cage topology. They just seem like separate solutions to me.


 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top