Velocity Reviews > C++ > Find number of legs on a farm...

# Find number of legs on a farm...

Petrakid
Guest
Posts: n/a

 10-10-2006
Hey, I have a task to complete. I am trying to figure out the best
way, in C++ to determine the following. There is this farm with pigs
and chickens. Only the legs of the pigs and chickens look exactly the
same, so for a short person to determine how many possible pigs and how
many possible chickens, all they can do is count the total legs of the
two.

- Chickens seem to always run around in groups of 3
- Pigs seem to always clump together in groups of 8
- pigs ALWAYS have 4 legs and chickens ALWAYS have 2 legs

I need to figure out the total number of possibilities ( like there are
300 different possibilities) AND list the possibilities at the users
request (8 pigs and 3 chicken or 600 pigs and 89 chickens, etc).

I CANNOT use arrays or the exact chinese remainder theorem (i can use a
variation of it).

this is an assignment, so I don't need the complete answer. I'm having
the most trouble with the calculation steps.

I've already determined that there will be 2 calculation functions,
though if it can be done with 1 calculation function, that's great.

If yo could help me out, I would appreciate it!!!!!

Alf P. Steinbach
Guest
Posts: n/a

 10-10-2006
* Petrakid:
>
> this is an assignment, so I don't need the complete answer.

Good.

Hth.,

- Alf

--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?

Victor Bazarov
Guest
Posts: n/a

 10-10-2006
Petrakid wrote:
> Hey, I have a task to complete. I am trying to figure out the best
> way, in C++ to determine the following. There is this farm with pigs
> and chickens. Only the legs of the pigs and chickens look exactly the
> same, so for a short person to determine how many possible pigs and
> how many possible chickens, all they can do is count the total legs
> of the two.
>
> - Chickens seem to always run around in groups of 3
> - Pigs seem to always clump together in groups of 8
> - pigs ALWAYS have 4 legs and chickens ALWAYS have 2 legs
>
> I need to figure out the total number of possibilities ( like there
> are 300 different possibilities) AND list the possibilities at the
> users request (8 pigs and 3 chicken or 600 pigs and 89 chickens, etc).
>
> I CANNOT use arrays or the exact chinese remainder theorem (i can use
> a variation of it).
>
> this is an assignment, so I don't need the complete answer. I'm
> having the most trouble with the calculation steps.
>
> I've already determined that there will be 2 calculation functions,
> though if it can be done with 1 calculation function, that's great.
>
> If yo could help me out, I would appreciate it!!!!!

Well, you have the number of legs, right? You need to figure out
all solutions of

x*3*2 + y*8*4 = N

where 'N' is the number of legs and 'x' and 'y' is the number of
groups of chickens and pigs, respectively. Then you multiply the
'x' by 3 and you get the number of chickens. And my multiplying
'y' by 8 you get the number of pigs.

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask

Frederick Gotham
Guest
Posts: n/a

 10-10-2006
Petrakid posted:

> There is this farm with pigs
> and chickens.

Cool, I like pigs and chickens.

> Only the legs of the pigs and chickens look exactly the
> same,

Extrememly ambiguous statment.

> so for a short person to determine how many possible pigs and how
> many possible chickens, all they can do is count the total legs of the
> two.
>
> - Chickens seem to always run around in groups of 3

That's 6 legs per group then no?

> - Pigs seem to always clump together in groups of 8

That's 32 legs per group, no?

> - pigs ALWAYS have 4 legs and chickens ALWAYS have 2 legs

OH MY GOD ARE YOU SERIOUS?

> If yo could help me out, I would appreciate it!!!!!

If there are 192 legs, then there could be:

(1) Thirty-two groups of chickens, zero groups of pigs.
(2) Six groups of pigs, zero groups of chickens.

Here's how _I_ would go about it:

Start off with the original figure like "92 legs".

(1) Subtract 32 from it.
(2) See if the result % 6 is false.
(3) If so, you have a combination.
(4) Repeat until result < 32

Then do it with 6:

(1) Subtract 6 from it.
(2) See if the result % 32 is false.
(3) If so, you have a combination.
(4) Repeat until result < 6.

Something along those lines in anyway.

--

Frederick Gotham

Petrakid
Guest
Posts: n/a

 10-10-2006
Thanks for the help I'll start plugging in the calculations tonight.
Yeah, yeah I had to make sure everyone understood that the pigs and
chickens aren't deformed or genetically modified in any way!!

Any further ideas are still welcome!

Petrakid wrote:
> Hey, I have a task to complete. I am trying to figure out the best
> way, in C++ to determine the following. There is this farm with pigs
> and chickens. Only the legs of the pigs and chickens look exactly the
> same, so for a short person to determine how many possible pigs and how
> many possible chickens, all they can do is count the total legs of the
> two.
>
> - Chickens seem to always run around in groups of 3
> - Pigs seem to always clump together in groups of 8
> - pigs ALWAYS have 4 legs and chickens ALWAYS have 2 legs
>
> I need to figure out the total number of possibilities ( like there are
> 300 different possibilities) AND list the possibilities at the users
> request (8 pigs and 3 chicken or 600 pigs and 89 chickens, etc).
>
> I CANNOT use arrays or the exact chinese remainder theorem (i can use a
> variation of it).
>
> this is an assignment, so I don't need the complete answer. I'm having
> the most trouble with the calculation steps.
>
> I've already determined that there will be 2 calculation functions,
> though if it can be done with 1 calculation function, that's great.
>
> If yo could help me out, I would appreciate it!!!!!

Jim Langston
Guest
Posts: n/a

 10-10-2006
"Petrakid" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed) ups.com...
> Thanks for the help I'll start plugging in the calculations tonight.
> Yeah, yeah I had to make sure everyone understood that the pigs and
> chickens aren't deformed or genetically modified in any way!!

I once met a farmer who had chickens with three legs. I asked what the heck
these were, he said him, ma and his son all liked chiken legs so they
developed a breed with three legs. I asked him how they tasted. He said he
didn't know, wasn't able to catch one yet.

>
> Any further ideas are still welcome!
>
> Petrakid wrote:
>> Hey, I have a task to complete. I am trying to figure out the best
>> way, in C++ to determine the following. There is this farm with pigs
>> and chickens. Only the legs of the pigs and chickens look exactly the
>> same, so for a short person to determine how many possible pigs and how
>> many possible chickens, all they can do is count the total legs of the
>> two.
>>
>> - Chickens seem to always run around in groups of 3
>> - Pigs seem to always clump together in groups of 8
>> - pigs ALWAYS have 4 legs and chickens ALWAYS have 2 legs
>>
>> I need to figure out the total number of possibilities ( like there are
>> 300 different possibilities) AND list the possibilities at the users
>> request (8 pigs and 3 chicken or 600 pigs and 89 chickens, etc).
>>
>> I CANNOT use arrays or the exact chinese remainder theorem (i can use a
>> variation of it).
>>
>> this is an assignment, so I don't need the complete answer. I'm having
>> the most trouble with the calculation steps.
>>
>> I've already determined that there will be 2 calculation functions,
>> though if it can be done with 1 calculation function, that's great.
>>
>> If yo could help me out, I would appreciate it!!!!!

>

Kevin Handy
Guest
Posts: n/a

 10-11-2006
Petrakid wrote:
> Hey, I have a task to complete. I am trying to figure out the best
> way, in C++ to determine the following. There is this farm with pigs
> and chickens. Only the legs of the pigs and chickens look exactly the
> same, so for a short person to determine how many possible pigs and how

How short is this person, that he can't see over the top of a chicken?
Or are these those strange KFC critters?

> many possible chickens, all they can do is count the total legs of the
> two.
>
> - Chickens seem to always run around in groups of 3
> - Pigs seem to always clump together in groups of 8
> - pigs ALWAYS have 4 legs and chickens ALWAYS have 2 legs

What about the "he was too good to eat all at once" thing?

Are you really ruling out KFC chickens? Then your guy must be really
really short.

> I need to figure out the total number of possibilities ( like there are
> 300 different possibilities) AND list the possibilities at the users
> request (8 pigs and 3 chicken or 600 pigs and 89 chickens, etc).
>
> I CANNOT use arrays or the exact chinese remainder theorem (i can use a
> variation of it).

What is the "chinese remainder theorem"?

> this is an assignment, so I don't need the complete answer. I'm having
> the most trouble with the calculation steps.

Don't worry about individual critters. Handle them as
a '3-chicken' with 6 legs, or a '8-pig' with 32 legs.
Then just loop through all possible 8-pigs, and see if
the remainder fits as a 3-chicken (no left over legs,
which would get messy).

> I've already determined that there will be 2 calculation functions,
> though if it can be done with 1 calculation function, that's great.
>
> If yo could help me out, I would appreciate it!!!!!
>

You should then target the e-mail at 'yo', whoever he is.

----== Posted via Newsfeeds.Com - Unlimited-Unrestricted-Secure Usenet News==----
http://www.newsfeeds.com The #1 Newsgroup Service in the World! 120,000+ Newsgroups
----= East and West-Coast Server Farms - Total Privacy via Encryption =----

Petrakid
Guest
Posts: n/a

 10-11-2006
Alright, now if I wanted to do this as a range (say numbers between
500-1000), what would I do? Sorry to ask these things, but the
instructor tends to be pretty vague when it comes to this stuff, and
i'm using any resource i can to find help

Thanks

Petrakid wrote:
> Hey, I have a task to complete. I am trying to figure out the best
> way, in C++ to determine the following. There is this farm with pigs
> and chickens. Only the legs of the pigs and chickens look exactly the
> same, so for a short person to determine how many possible pigs and how
> many possible chickens, all they can do is count the total legs of the
> two.
>
> - Chickens seem to always run around in groups of 3
> - Pigs seem to always clump together in groups of 8
> - pigs ALWAYS have 4 legs and chickens ALWAYS have 2 legs
>
> I need to figure out the total number of possibilities ( like there are
> 300 different possibilities) AND list the possibilities at the users
> request (8 pigs and 3 chicken or 600 pigs and 89 chickens, etc).
>
> I CANNOT use arrays or the exact chinese remainder theorem (i can use a
> variation of it).
>
> this is an assignment, so I don't need the complete answer. I'm having
> the most trouble with the calculation steps.
>
> I've already determined that there will be 2 calculation functions,
> though if it can be done with 1 calculation function, that's great.
>
> If yo could help me out, I would appreciate it!!!!!

osmium
Guest
Posts: n/a

 10-11-2006
"Petrakid" writes:

> Alright, now if I wanted to do this as a range (say numbers between
> 500-1000), what would I do? Sorry to ask these things, but the
> instructor tends to be pretty vague when it comes to this stuff, and
> i'm using any resource i can to find help

I assume "this" means you want the user to enter numbers only in the range
300-500. If the user enters a number outside of that range, tell him the
rules (again, perhaps) and tell him to re-enter the number. Note that the
valid entries always take the form:

n = 6c + 32 p
where c is the number of groups of chickens and p is the number of groups
of pigs.

Petrakid
Guest
Posts: n/a

 10-11-2006
Not necessarily. The range should be kept limited to keep the
processor from going crazy, but there is no limit to the range in the
program - just in the instructions.

Regardless, i'm assuming that the same formula n = 6c + 32p still
stands.

osmium wrote:
> "Petrakid" writes:
>
> > Alright, now if I wanted to do this as a range (say numbers between
> > 500-1000), what would I do? Sorry to ask these things, but the
> > instructor tends to be pretty vague when it comes to this stuff, and
> > i'm using any resource i can to find help

>
> I assume "this" means you want the user to enter numbers only in the range
> 300-500. If the user enters a number outside of that range, tell him the
> rules (again, perhaps) and tell him to re-enter the number. Note that the
> valid entries always take the form:
>
> n = 6c + 32 p
> where c is the number of groups of chickens and p is the number of groups
> of pigs.