So I'm tutoring at the library and an elementary or pre K student shows me a sheet with one problem on it:

Put 9 pigs into 4 pens so that there are an odd number of pigs in each pen.

I tried to solve it and failed! Does anybody know how to solve this? This question seems ridiculously difficult and impossible IMO.

Maximilian Janisch
  • 12,071
  • 2
  • 15
  • 41
  • 5,419
  • 10
  • 37
  • 53
  • Please post this as an answer so that we can put this one to bed! – Old John Nov 07 '13 at 00:25
  • I'm assuming this was a typo. While the three pen into one pen solution works, I doubt that's what the person who constructed the assignment intended for an elementary school student. – joejacobz Nov 07 '13 at 00:45
  • 15
    Surely you are not suggesting that school teachers would never ask a trick question? – Old John Nov 07 '13 at 01:11
  • @joejacobz I would bet that about as many later elementary school students could come up with a solution as adults, but certainly not as young as OP says. It's a thinking outside the box exercise, which young students should expect to run into frequently (I certainly did). Besides, there are other solutions; the key is just the realization that it would be impossible _if_ the pens were disjoint. ex. $1..2..3..4...4321$. – Jaycob Coleman Nov 07 '13 at 01:13
  • 11
    The question fails to make it clear that a total number of 9 pigs is to be distributed into four pens; a possible interpretation is simply to put 9 pigs into each of four pens. This kind of imprecise language is one reason why users ask for one thing, but the software which is implemented does something else. :) – Kaz Nov 07 '13 at 03:34
  • 4
    Any kid that realizes pens can be nested has probably been coding in Lisp recently. – Kaz Nov 07 '13 at 03:35
  • 144
    This question is silly. You can't fit nine pigs into a pen. Only ink goes in pens. You have to liquidize the pigs into pig ink, and then you can divide the pig ink equally into four portions. – Crashworks Nov 07 '13 at 03:43
  • 11
    As far as I know, in my Ontarian school board, teachers ("good" or "bad" alike) wouldn't give questions like these without explicitly telling them that they are meant to be riddles. It would hurt the confidence of the students and become political. Perhaps this child knew it was a riddle and wanted to share it for the fun of it. – SimonT Nov 07 '13 at 04:06
  • 1
    If I had to guess on how this problem came up is that they were talking about the integers, which lead to free groups, which lead to the Banach-Tarski paradox. –  Nov 07 '13 at 04:46
  • 1
    Coming from somewhere that doesn't have "elementary or pre K student"s, what age are "elementary or pre K student"? Not that it changes the question of course! – Rich Nov 07 '13 at 05:54
  • 2
    @Rich Generally 12 and under. – Jaycob Coleman Nov 07 '13 at 07:03
  • @SimonT I agree that these types of questions should only be given in the proper context, such as other trick questions. – Jaycob Coleman Nov 07 '13 at 07:04
  • https://www.google.com/search?q=pig+pen&tbm=isch – Carsten S Nov 07 '13 at 08:59
  • @joejacobz Elementary school teachers thrive on trick questions. I remember a trick _test_ in 1st grade where the only correct way to complete it was to write your name and turn it in blank, due to how she worded the instructions. Luckily it was just a joke, as only 1 person got it. – Izkata Nov 07 '13 at 13:54
  • Does the word "pig" have a homophonic word or are those guys trying to put swines into the pens? – Zafer Sernikli Nov 07 '13 at 14:13
  • 2
    Ouw, it's "pen" which has a homophonic =) I'm trying to imagine pigs being put into the pens, which are being used for writing =) – Zafer Sernikli Nov 07 '13 at 14:24
  • 1
    The question doesn't explicite states that after putting pigs in pens, each pig should be in a pen.... – Danubian Sailor Nov 08 '13 at 07:56
  • 9
    One does not simply... http://imgur.com/vF5b3mf – Simone Nov 08 '13 at 10:16
  • Just my 2¢... I'm not native English speaker, sorry... I don't understand if it's clear to anybody, but "pen" is an ancient (I suppose) synonym for "fence"... (http://en.wikipedia.org/wiki/Pen_(disambiguation) – MarcoS Nov 08 '13 at 10:45
  • 1
    @MarcoS Yes, in this context "pen" is synonymous to a fenced area. – zerosofthezeta Nov 08 '13 at 17:28
  • 2
    @Crashworks Ink goes into pens, but oinks come out of pigs! – Bruno Joyal Nov 08 '13 at 22:46
  • 2
    You put one pig in the first pen, one in the second, one in the third and six in the fourth, which is certainly an odd number of pigs to put in that pen. – Syd Henderson Nov 08 '13 at 22:57
  • 2
    @MarcoS We are making silly puns. The teacher asked a trick question, so we're making up even trickier answers that play on double meanings. – Crashworks Nov 08 '13 at 23:14
  • Unless, there is a chainsaw involved, you cannot. – ggdx Nov 09 '13 at 18:44
  • You put 3 pigs into first 3 pens, and remaining 6 pigs into the fourth pen. Then you crawl into the fourth pen. – Julian Wergieluk Nov 19 '13 at 17:39
  • 1
    In each pen there should be an odd number of pigs. We are summing odd+odd+odd+odd= (odd+odd)+(odd+odd) = even+even= even. Therefore if the number of pigs in each pen is odd then the total number of pigs has to be even assuming of course that pens are disjoint. – Adam Nov 23 '13 at 01:18
  • How about "Put 9 *pens* into 4 *pigs* so that there are an odd number of pens in each pig." – hola Dec 01 '19 at 14:33

18 Answers18


Since this has been exposed, some claim, to be a riddle and not a bona fide math question, why not completely drive the stake through its heart:

Pen 1: 7 pigs

Pen 2: 1 pig

Pen 3: 3 pigs

Pen 4: -2 pigs

Now the astute reader will note that -2 pigs is a pretty darn odd number of pigs to be in a pen!

  • 6,671
  • 1
  • 17
  • 30

It appears to be a trick question.

Make 3 pens, put 3 pigs in each pen. Then put a 4th pen around all 3 of the other ones, and you have 9 pigs in that pen.


@MJD found a source for this problem with solution, see Boys' Life magazine from 1916.

  • 55,120
  • 25
  • 75
  • 108
  • 2
    Thanks! I let the student know this answer and the not possible option as well. – zerosofthezeta Nov 07 '13 at 00:38
  • You are quite welcome! Have fun with the students. Regards – Amzoti Nov 07 '13 at 00:40
  • 20
    The trick is good (though I do not see why not just to build 4 nested pens and put all pigs into the innermost one). There are many other solutions in the same spirit (using the ambiguity in the problem statement). We can build 4 disjoint pens, put one pig in each of the first 3 and 6 in the fourth and let somebody try to convince us that there aren't 3 pigs in the last pen (if we have 6, we certainly can point out three (an odd number) of them that *are* in the pen). Another option is to have one extra pig in one pen (that the pens must be *empty* is as unclear as that they must be disjoint). – fedja Nov 07 '13 at 02:01
  • 56
    Basically, this is a riddle, not a maths question. – TRiG Nov 07 '13 at 02:58
  • 63
    Even simpler: if pens can be nested, then simply make this quadruple-walled pen: [[[[ 9 pigs ]]]]. Why go through all the trouble of dividing into groups of three? – Kaz Nov 07 '13 at 03:36
  • 1
    This kind of riddle questions is what I call a "Aha" question. These are usually easy questions designed to force people "out of the frame". The "frame" is something the problem does not state but to which most users will stick anyway. Another classical such problem: 1, 11, 21, 1211, 111221, find the next number in the numerical sequence, or draw a figure linking 9 points (on a regular grid) with only 4 lines. Learning to think outside the frame is not so useless it can seem at first sight: think on the fifth Euclide's postulate of geometry. – kriss Nov 07 '13 at 08:31
  • 1
    BTW. How many ways are there to solve the problem?... – Kostya Nov 07 '13 at 09:15
  • @kriss Interestingly, the 9 dots puzzle is believed to be the origin of the phrase "thinking outside the box/frame/square." As much as I'd like to disclose the name of the sequence, that would ruin it for anyone just seeing it for the first time ;) Nice examples. – Jaycob Coleman Nov 07 '13 at 09:52
  • 1
    @Jaycob Coleman: let's call it "The Conway sequence" :-) it shouldn't ruin it. – kriss Nov 07 '13 at 10:43
  • This is an old chestnut. For example, [here is a citation from 1977](http://books.google.com/books?id=g2s1AAAAMAAJ&q=%22nine+pigs+into+four+pens%22&dq=%22nine+pigs+into+four+pens%22&hl=en&sa=X&ei=Xbx7UpGFKInmsAS_wIC4Cg&ved=0CC0Q6AEwAA), although I believe it is much older—I would be surprised if it couldn't be found in the work of Sam Loyd or H.E. Dudeney. Your idea is the one that is usually given. – MJD Nov 07 '13 at 16:15
  • Here it is, with the solution you have, [in *Boys' Life* magazine from 1916](http://books.google.com/books?id=WOAyGmqvVfkC&pg=PA48&dq=%22nine+pigs+in+four+pens%22&hl=en&sa=X&ei=9rx7Uo28JsrnsAT81YKAAQ&ved=0CD8Q6AEwAQ#v=onepage&q=%22nine%20pigs%20in%20four%20pens%22&f=false). – MJD Nov 07 '13 at 16:18
  • @MJD: Amazing find! Also, we seemed to have challenged younger students in much different ways. Another example was to recent 100-year grade school exam that had a math section and how many people today could pass it. Thanks for finding it! Regards – Amzoti Nov 07 '13 at 16:21
  • Actually, the solution has a realistic aspect. Though pig keepers are not going to nest pig pens, realistic, suppose prisoners in the USA were allowed to keep pigs. Then it would not be unusual to have three pig pens inside one state pen. – Kaz Nov 07 '13 at 17:11
  • @Kaz But you'd have zero pigs inside some pens, right? I mean, if you count the pen to be the annular region, that is. – Pedro Nov 07 '13 at 17:16
  • Notice the problem doesn't say "Divide" nine pigs into four pens, it says put nine pigs in four pens. So the answer is simple. Put nine pigs in the first pen, another nine pigs in the second, another nine pigs in the third, and another nine pigs in the fourth. – Kevin Nov 07 '13 at 17:26
  • @Kevin I made essentially the same comment 13 hours ago, under the question. Great minds think alike! :) – Kaz Nov 07 '13 at 17:34
  • Note that the wording in Boys' Life is quite different: "A farmer had nine pigs. He built four pens and put and odd number of pigs in each pen. How did he do it?" The wording in the question here on Math.SE implies that the pens already exist, not that they can be manipulated. – Kyralessa Nov 07 '13 at 18:28
  • Dear @MJD: how did you find your wonderful reference to *Boys' Life* ? – Georges Elencwajg Nov 07 '13 at 18:39
  • 1
    I just did Google Book Search for "nine pigs in four pens". Sometimes knowing to look is all that is needed. – MJD Nov 07 '13 at 18:42
  • 10
    I wonder how well this riddle would go over with an 8-year old who lives on a farm? Surely farmers don't nest pig pens and would not even consider thinking about such a thing valid? – Michael Nov 07 '13 at 19:10
  • 23
    @Michael I wonder if this is also harder for those familiar with sets, who'd point out that $\{\{\{\{\bullet\}\}\}\}$ isn't four sets each containing $\bullet$, but a three sets that each contain one set, and one set that contains $\bullet$. Those familiar with strongly typed collections in programming languages would also complain that you can't put a `Pig` into a `Set>`. – Joshua Taylor Nov 07 '13 at 22:12
  • Thanks for that Boy's Life magazine link! That Colgate toothpaste ad is going to the printer and on my wall. If someone comes here with bad breath, they will be pointed in its direction. I had no idea the Meccano construction set was so freakin' old! – Kaz Nov 08 '13 at 00:28
  • @Joshua Taylor: Maybe it's more useful to think of each pen as an array. Just because pen2 contains a subset of the pigs in pen1 doesn't mean pen2 is an element of pen1, visual representation aside. If we were then to assume that the pens can be any shape and that their boundaries can overlap we could end up with a Venn (Pen?) diagram with even more possible solutions. EDIT: I guess I just described swish's solution below. – Eric N Nov 08 '13 at 15:10
  • [I said earlier](http://math.stackexchange.com/questions/555024/how-to-put-9-pigs-into-4-pens-so-that-there-are-an-odd-number-of-pigs-in-each-pe/555028#comment1181726_555028) that I expected it could be found in the work of Sam Loyd or H.E. Dudeney, and [indeed it is](https://books.google.com/books?id=-jNjkPXgZgwC&lpg=PA6&ots=Ms_Scb1Fd7&dq=pigs%20in%20pens%20puzzle%20%22sam%20loyd%22&pg=PA6#v=onepage&q&f=false). This version was published no later than 1914. – MJD Jan 12 '17 at 20:26

Lemma: $-\frac{1}{12}$ is an integer.

proof: Consider the Riemann zeta function $\zeta$ evaluated at $-1$. By analytic continuation, $\zeta(-1) = -\frac{1}{12}$. However, we also have the series expansion $\zeta(s)=\displaystyle \sum_{n=1}^\infty n^{-s}$, so (ignoring issues with convergence), $\zeta(-1)=1+2+3+\cdots$. This is an infinite sum of integers. Any finite sum of integers is an integer, and the since the integers are a closed set (and hence contain all limit points) this also holds in the limiting case. Hence $-\frac{1}{12}$ is an integer.

Corollary $\frac{2}{3}$ is odd.

proof: By above, since $-\frac{1}{12}$ is an integer, $4 (-\frac{1}{12})=-\frac{1}{3}$ is an even integer. Since the successor of any even integer is odd, $-\frac13 +1 = \frac23$ is odd.

Theorem It is possible to put 9 pigs in 4 pens such that each pen has an odd number of pigs.

proof: For the first pen, put $7$ of the pigs in. Cut the remaining $2$ pigs into equal thirds and put two of the thirds in each of the remaining pens. Since $7=2\times3+1$, $7$ is odd. By corollary above, $\frac23$ is odd. Hence all four pens have an odd number of pigs.

Note: The above is humor.

Logan M
  • 6,771
  • 3
  • 29
  • 45

It's not possible. Adding an even number of odd numbers will give an even number: $(2a+1) + (2b+1) = 2(a+b+1)$.

Najib Idrissi
  • 50,816
  • 9
  • 102
  • 179
  • 57
    This is the correct solution. Kids who grow up on trick questions just end up being a bunch of smart ass. Methodological, evidence based argument should be what they are accustomed to. – Sleeper Smith Nov 07 '13 at 03:16
  • 36
    @SleeperSmith but what if life is a trick question? – Andy Nov 07 '13 at 04:47
  • 4
    @AndyPryor Trust me it isn't. Your parents would've picked your high school, college doctor/law degree, PHD, arranged marriage, asked favor for you to start at a big firm, decided the number of kids you should have.... If you are a chinese. (I'm a chinese. No that's a tongue in cheek joke. :p) – Sleeper Smith Nov 07 '13 at 04:50
  • 3
    @SleeperSmith There is something to be said for this from the standpoint of mastering technique, sir. But don't you think a dose of these "trick" questions might encourage creative thinking? This might be a soft skill, but it is an important one, especially for the many who do not pursue a rigorous adult eduction (*many* adults), or who must make abstract connections (ie, politicians.) – user1833028 Nov 08 '13 at 05:15
  • It may be possible if you nest pens... – alinsoar Dec 23 '21 at 01:21

Put 9 pigs into 4 pens so that there are an odd number of pigs in each pen.

What about the simplest solution? The case where the pens are 'embedded' within each other:

pigs in pens

Four pens, Nine in each. Nine is odd.

  • 721
  • 4
  • 4

I think I finally got the teachers intended solution ;)

A pen is a closed fence, and since the earth is spherical there is no preferred side of the fence which is the enclosed one. Solution: Put 9 pigs anywhere, put 4 separate pens beside them.


There is many ways to do it. The real question is: how many? I wonder does the last in this picture counts?


  • 850
  • 1
  • 7
  • 17
  • 7
    To stay on the sensible (materially possible) side, I would propose that pens should be either disjoint or fully included in a larger one (intersection or any two pen is either empty or the smaller pen). That would exclude the last one (and the next to last has a pen with six pigs and should also be excluded). Now the problem begins to be interresting. Looks like a Lisp parenthesing problem. – kriss Nov 07 '13 at 12:50
  • @kriss Thx, next to last was wrong indeed (also the second one), counting to five is hard! Fixed it and also colored the pens for more clearity. – swish Nov 07 '13 at 13:50

Put 9 pigs into 4 pens so that there are an odd number of pigs in each pen. enter image description here

Each of pens $1,2,3,$ and $4$ have an odd number of pigs in them with $1$ each. The last $5$ pigs are liberally interpreted as being 'put into' the $4$ pens. Though they aren't inside one of the four pens they're inside the four pens.

I didn't see this in the pictured solutions so I thought I'd add it. Apologies if it was already mentioned. It was however mentioned that you could put $1$ in each of the $4$ pens and let the other $5$ roam free. But, what good are your pigs if when you want bacon you discover they walked away? This fixes your bacon in place. Nevertheless, I had fun drawing piggy banks!

  • 2,253
  • 2
  • 28
  • 53

Put one in each pen and let the other 5 roam.

No one said they all had to be enclosed in pens when you were done.

  • 241
  • 1
  • 10

Here are 88 solutions (I believe this is all of them):

Joe K
  • 1,885
  • 1
  • 11
  • 10

Suppose you have 4 pens. An odd number looks like this: $2a + 1$ for some integer $a \ge 0$. Now make for pens and add.

$$2a+1+2b+1+2c+1 +2d+1 = 2(a+b+c+d) + 4 = 2(a+b+c+d+2).$$

The result is even.

  • 47,689
  • 3
  • 75
  • 127

Nobody said the pens were disjoint. With non-disjoint pens, there are many solutions.

Robert Israel
  • 416,382
  • 24
  • 302
  • 603

Just put the pigs in the first pen, then put that pen inside the next pen, etc.

The last pen will contain a pen that contains a pen that contains a pen that contains 9 pigs, but all 4 pens will contain 9 pigs.

You could also put 3 pigs each in 3 pens, and put those 3 pens inside the bigger pen.

  • 51
  • 1

The problem as stated is impossible under the usual interpretation, because the sum of four odd numbers will be even, and so can't equal $9$. But the trick question interpretation from Amzoti's comment/answer seems pretty plausible!

Matt E
  • 118,032
  • 11
  • 286
  • 447

Put 6 pigs in the first pen, then 1 pig in each subsequent pen. Don't feed the pigs in the first pen. The first pen will contain an odd number of pigs soon enough.

Another option is to make sure that of the 6 pigs in the first pen, one is the mother, the remainder being piglets and hope for the worst. Same result. That's how pigs get down.

  • 157
  • 4
  • Horrible, yes. But logically, what's wrong with questioning the mathematical model that pairs integers with pigs? They can indeed literally disintegrate. – minopret Nov 09 '13 at 02:21
  • @minopret I suspect that everything was wrong with every facet of this question... – Tonithy Nov 09 '13 at 02:25

Let's rephrase the problem using well defined mathematical terms: as far as I know pigs and pens are not such well defined unambiguous mathematical terms.

Maybe something like:

Dispatch integers from 1 to 9 between 4 sets of integers.

It becomes obvious that it is impossible if sets are disjoint, and trivial if they are not.

And as more "classical" question we could also ask how many ways there is to dispatch these integers between 4 sets where number of items in every set is odd.

  • 809
  • 9
  • 12
  • Forgive me for not being knowledgeable in this subject area, but how would one go about proving that it is impossible to do this for disjoint sets? I find this question/riddle/problem intriguing. – jacobq Feb 12 '14 at 07:02
  • Would it be similar to Matt E's answer about the sum of 4 odd integers always being even? – jacobq Feb 12 '14 at 07:04
  • I call it obvious because I can proove it with a direct enumerative approach. You must put at least 1 pig in each pen because 0 is even, but if you put 1 in the first 3 pens you get 6 in the last one. Now to fix that you must remove at least one pig from the largest pen. 1 won't do (because the pig will make the target pen even, 2 or 4 won't do because the source pen will have an even number of pigs, 3 and 5 similarly won't do if you examine all possible dispatchs. Of course there are other ways to prove it (and generalise it), but the above reasoning is enough. – kriss Feb 12 '14 at 08:21

Just put all the 9 pigs within a pen. Then build a second pen all around the first, a third one all around the second and so on. You will end up by having each pen containing an odd number of pigs.


I assume in elementary school they are not expected to know the parity of zero, so why not this:


Thats 9, and all "not even" (again, forget about the parity of zero).

  • 14
    I don't think it's unreasonable for elementary school students to know the parity of zero. And if they really don't know, how can they be expected to use it in the solution? Not to mention that this solution is just purely wrong. – EuYu Nov 07 '13 at 03:02
  • 3
    I don't understand all the down votes. In elementary school, I didn't know that 0 was even. I thought it was capable of both, just like from a theoretical point of view, you could have positive zero and negative zero. Didn't know this was such a serious question. No body else took it seriously, especially the "put three pens inside the fourth" answers. That's clearly not the answer either. – Nicholas Yost Nov 07 '13 at 14:15
  • It's certainly not an odd number though! – James Nov 07 '13 at 14:19
  • 20
    @NicholasYost Because you can't use lack of knowledge to prove things. It's like saying "Just make 1 pen with all the pigs in it because I didn't know $1 \neq 4$" – Michael Mrozek Nov 07 '13 at 15:40
  • 1
    You also can't have positive zero and negative zero. You can put a plus or a minus sign in front of it, but it still just equals zero. Indeed, any reasonable definition of "positive" or "negative" usually boils down to be greater than or less than zero. – Jeremy West Jan 11 '14 at 05:50