This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Programming Diversions and the fly likes Egg 'n bacon Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Other » Programming Diversions
Bookmark "Egg Watch "Egg New topic
Author

Egg 'n bacon

HS Thomas
Ranch Hand

Joined: May 15, 2002
Posts: 3404
Jessica raises pot-bellied pigs and ostriches.
Among her animals she has 17 heads and 56 legs.
How many pigs and ostriches does she have ?
regards
Jason Menard
Sheriff

Joined: Nov 09, 2000
Posts: 6450
6 ostriches and 11 pigs.
The Math:
x = # of ostrich legs, x/2 = # of ostriches
y = # of pig legs, y/4 = # of pigs
x + y = 56
x/2 + y/4 = 17
y = 56 - x
x/2 + (56 - x)/4 = 17
4(x/2 + (56 - x)/4) = 4 * 17
2x + 56 - x = 68
x = 12
y = 56 - 12 = 44
x/2 = 6
y/4 = 11
[ September 10, 2003: Message edited by: Jason Menard ]
HS Thomas
Ranch Hand

Joined: May 15, 2002
Posts: 3404
Congrats.
I did it the usual (longer) way using math.
Here is a solution that uses pure logic.
Each animal has two hind legs, so 17 heads means 34 hind legs total.
The remaining 22 legs must be the front legs of 11 four-legged pigs.
Therefore 11 heads belong to the pigs and the remaining 6 heads belong to ostriches.
regards
Bert Bates
author
Sheriff

Joined: Oct 14, 2002
Posts: 8801
    
    5
How do you count cows in a pasture?
.
.
.
.
.
.
.
.
.
Count their legs and divide by four.


Spot false dilemmas now, ask me how!
(If you're not on the edge, you're taking up too much room.)
 
Don't get me started about those stupid light bulbs.
 
subject: Egg 'n bacon
 
Similar Threads
WA #1.....word association
Pigs in pens
Learning a language
Would you fight a giant chicken?
capitalization on the net