Constraints in Girls and Pigs problem

Back to General discussions forum

qwerty     2025-04-10 14:49:14

There are two constraints in problem that is not mentioned in problem statement:

  1. Obvious one: because number of breasts is always greater than number of legs, number of pigs is always greater than zero.
  2. Not obvious one: number of girls, too, should be greater than zero. With 32 legs and 176 breasts we have 6 solutions, including solution with 0 girls and 8 pigs with 22 breasts each, but checker disagrees and counts only 5 solutions.

I read many of other solutions and it seems that most people are not aware of second constraint.

Hoperfully this help someone to save hours debugging!

Zigrik     2025-04-11 11:07:05
User avatar

"..The girls are pasturing pigs at the field..." it seems like it's being said that there are girls on the field, so there are more than 0 of them))

qwerty     2025-04-11 13:47:40

Good point! Definitely there should be someone pasturing the pigs, or some of them may get lost, and my solutiong become wrong :).

Rodion (admin)     2025-04-11 15:45:24
User avatar

Though I'm not quite sure about what was meant when writing the statement, I suspect that all the three unknown values should be non-negative integers.

When I proposed the problem to school kids I got various additional questions:

  • are there only female pigs
  • do all pigs have the same number of breasts

and even more wild ideas about possibly one-legged girls included into number of shepherdesses

not pondering on social and biological aspects of all those questions, I generally point out that any of them leads to problem becoming unsolvable (or allowing too large number of solutions) which, out of common sense, seems to be not our goal :)

Please login and solve 5 problems to be able to post at forum