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!!!!! 16 4406
* 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?
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
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
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!!!!!
"Petrakid" <pe******@gmail.comwrote in message
news:11**********************@m7g2000cwm.googlegro 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!!!!!
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!!!!!
"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.
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.
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 =----
Got that part and yes these chicken are VERY BIG KFC chicken - they can
kill!!
Check out http://groups.google.com/group/comp....b5d26831cce7e2
to see where I'm at now.j
Thanks!!
Kevin Handy wrote:
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 =----
"Kevin Handy" <kt*@srv.netwrote in message
news:11**************@sp6iad.superfeed.net...
Petrakid wrote:
What is the "chinese remainder theorem"?
http://www.cut-the-knot.org/blue/chinese.shtml
oddly enough...
>
You should then target the e-mail at 'yo', whoever he is.
can't argue with that.
----== 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
=----
It wasn't me who asked that - I know what the theorem is - i just can't
use it...directly...in the program.
I got the program printing out numbers now, and printing out the total
of possible solutions, but the solutions and numbers it's printing
aren't right.
So the program itself is setup right, it's just the arithmatic that is
wrong. I'm going through it step by step, and maybe I'll find the
problem. I also posted the program up here to look at, but I have
since changed it:
#include <iostream>
#include <iomanip>
using namespace std;
// Global Constants
const int min_cowboys = 3;
const int min_horses = 8;
const int legs_cowboys = 2;
const int legs_horses = 4;
const int COL_WIDTH = 10;
void Instructions();
void Print_Possibilities(int min, int max);
int Calculate_Possibilities(int min, int max);
int main()
{
int min_legs;
int max_legs;
int total_poss;
char answer;
void Instructions();
do
{
cout << "Please enter the lowest number in the range: ";
cin >min_legs;
cout << "Next, enter the highest number in the range: ";
cin >max_legs;
if (min_legs < (min_horses * legs_horses))
{
cout << "You have entered an invalid range!"<<endl;
} else
{
total_poss = Calculate_Possibilities(min_legs, max_legs);
cout << "There are a total of "<<total_poss<<" ways to
group this"<<endl;
cout << "many legs."<<endl;
cout << "Would you like to see the possibilities? ";
cin >answer;
if ((answer == 'y') || (answer == 'Y'))
{
cout <<setw(COL_WIDTH)<<"Cowboys";
cout <<setw(COL_WIDTH)<<"Horses"<<endl;
Print_Possibilities(min_legs, max_legs);
cout <<endl;
}
else
cout <<endl;
}
cout << "Would you like to try again? ";
cin >answer;
} while ((answer == 'y') || (answer == 'Y'));
return(0);
}
int Calculate_Possibilities(int min, int max)
{
int index;
int legs;
int possibilities;
for (legs = min; legs < max; legs++)
{
for (index = min_cowboys; index < legs; index++)
{
if ((index * legs_cowboys * min_cowboys) < legs)
{
if ((legs - index * legs_cowboys * min_cowboys) %
(min_horses * legs_horses) == 0)
{
possibilities++;
}
}
}
}
return(index);
}
void Print_Possibilities(int min, int max)
{
int index;
int legs;
for (legs = min; legs < max; legs++)
{
for (index = min_cowboys; index < legs; index ++)
{
if ((index * legs_cowboys * min_cowboys) < legs)
{
if ((legs - index * legs_cowboys * min_cowboys) %
(min_horses * legs_horses) == 0)
{
cout <<setw(COL_WIDTH)<<index * 3;
cout <<setw(COL_WIDTH)<<endl;
}
}
}
}
return;
}
void Instructions()
{
cout << "This program will look at a given range of numbers and
determine"<<endl;
cout << "the total number of possible leg combinations, given that
all"<<endl;
cout << "cowboys have 2 legs and all horses have 4 legs. It is
also given"<<endl;
cout << "that there are no less than 3 cowboys and no less than 8
horses in"<<endl;
cout << "the corral at any time. Because both cowboys and horses,
in general"<<endl;
cout << "have an even number of legs, no odd numbers will be
considered."<<endl;
return;
}
The calculation portion is a suggestion from a good friend of mine.
roy
Duane Hebert wrote:
"Kevin Handy" <kt*@srv.netwrote in message
news:11**************@sp6iad.superfeed.net...
Petrakid wrote:
What is the "chinese remainder theorem"?
http://www.cut-the-knot.org/blue/chinese.shtml
oddly enough...
You should then target the e-mail at 'yo', whoever he is.
can't argue with that.
----== 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 wrote:
// Global Constants
const int min_cowboys = 3;
const int min_horses = 8;
const int legs_cowboys = 2;
const int legs_horses = 4;
const int COL_WIDTH = 10;
Where did cowboys and horses come in (what no indians?) I thought we
were dealing with pigs and chickens.
Anyway, if we had groups of 32 and groups of 6, the first ambiguous
number would be 96. The highest even number that can't appear is 58.
Look, the person counting can't tell the difference between cowboys,
chickens, horses OR pigs. Do ya think it matters to them whether the
program prints out as cowboys or chickens? Obviously they aren't too
connected to reality anyway. :-D
Earl Purple wrote:
Petrakid wrote:
// Global Constants
const int min_cowboys = 3;
const int min_horses = 8;
const int legs_cowboys = 2;
const int legs_horses = 4;
const int COL_WIDTH = 10;
Where did cowboys and horses come in (what no indians?) I thought we
were dealing with pigs and chickens.
Anyway, if we had groups of 32 and groups of 6, the first ambiguous
number would be 96. The highest even number that can't appear is 58.
"Petrakid" wrote:
It wasn't me who asked that - I know what the theorem is - i just can't
use it...directly...in the program.
I got the program printing out numbers now, and printing out the total
of possible solutions, but the solutions and numbers it's printing
aren't right.
So the program itself is setup right, it's just the arithmatic that is
wrong. I'm going through it step by step, and maybe I'll find the
problem. I also posted the program up here to look at, but I have
since changed it:
I find your posting technique confusing. You now have two threads and two
sets of names (cowboys and pigs) for one problem. Then you post code for
people to "look at" but it is not your current code. Or is it the *problem*
you have changed, rather than the code?
Nevertheless, I will point out one fragment of this code that I find
interesting.
<snip>
int Calculate_Possibilities(int min, int max)
{
int index;
int legs;
int possibilities;
for (legs = min; legs < max; legs++)
{
for (index = min_cowboys; index < legs; index++)
{
if ((index * legs_cowboys * min_cowboys) < legs)
{
if ((legs - index * legs_cowboys * min_cowboys) %
(min_horses * legs_horses) == 0)
{
possibilities++;
How can it make sense to add something to possibilities? Since you didn't
initialize it, it contains garbage.
You also say in the rules that you will ignore odd numbers. Perhaps it is
there but I didn't see the code to back up that assertion.
Earl Purple wrote in message
<11**********************@h48g2000cwc.googlegroups .com>...
> Petrakid wrote:
>// Global Constants const int min_cowboys = 3; const int min_horses = 8; const int legs_cowboys = 2; const int legs_horses = 4; const int COL_WIDTH = 10;
Where did cowboys and horses come in (what no indians?) I thought we were dealing with pigs and chickens.
Sold the farm for a ranch!
If the three cowboys were on the horses (something ONLY the indians and Matt
Dillon could determine. [1]), then there would only be (min) 32 legs to
consider ( don't count the cowboy legs when they are on horses).
The cowboys ate the chickens and smoked the hams (oooou, the colors! the
colors!).
Huh?!?
To OP:
You did work all this out with pencil-n-paper before you started your code,
right??
It's SOP.
[1] - ref. Hollywood western movies.
--
Bob <GR
POVrookie This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Hidden Desi |
last post by:
Hi all,
I am implementing a .NET web application and extensively used the session
variables to store data. But today my manager told me that we will be
running that application in a web farm !!!!...
|
by: Paul Emory Sullivan |
last post by:
I anticipate a problem that may occur when we deploy our reports on
web farms. We have reports that generate both tabular and graphic
output in a single Recordset pass. Each report page request...
|
by: Steve |
last post by:
Hi
What is difference between web farm and web garden?
What i understand so far
Web Farm
Multi Server Environment
Support Session share
Application object not supported
Caching not...
|
by: LearninGuru |
last post by:
Hi Folks,
I am creating a web service that will be hosted on a web farm. The web service also uses sessions to store user specific data. I have the following doubts about session timeout in a...
|
by: Dominic |
last post by:
My question is about how to maintain view state in mobile ASP.NET
across postback / request in a web farm environment.
First of all, let's assume the web-farm does NOT use stick-session
feature....
|
by: robin9876 |
last post by:
When using the following code on a development server the page
redirects, however in a web farm environment the page does not
redirect.
Response.Redirect("a.aspx", False)
Both the...
|
by: Jeff |
last post by:
Hey
ASP.NET 2.0
I'm preparing for a www.123assess.com test and in that intention I yesterday
took a skill assessment test at microsoft.com. Today I'm reviewing some of
the questions I had...
|
by: =?Utf-8?B?VmlqYXkgQ2hpa3Rl?= |
last post by:
Hi Experts,
With Session Affinity and Web Server Farm on ISA Server 2006 accessing 2
backend IIS servers, I’m getting error “Validation of ViewState MAC failed.
If this application is hosted...
|
by: karthi84 |
last post by:
Hi,
I was asked to create a web application which is going to be running on a web farm. Now my questions are
1. I was asked to use windows authentication for connecting to SQL database, will...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
| |