Skip to content

Number of Pigs

Get access to track progress Get access to bookmark
Asset Pricingx / 34
Behavioral Questionsx / 7
Brain Teasersx / 78
Derivatives Theoryx / 107
Digital Assets - Cryptox / 82
Energy Tradingx / 55
Linear Algebrax / 24
Machine Learningx / 62
Math Questionsx / 49
Probability and Statisticsx / 219
Programmingx / 54
Totalx / 771
You walk into a barn and see a collection of pigs (P), chickens (C) and horses (H). You notice that there are 480 legs in total.
  • The number of chickens is twice the number of horses.
  • The number of pigs is twice the number of chickens.
Compute the number of pigs.
The provided info is:
  • The number of chickens (C) is twice the number of horses (H).
  • The number of pigs (P) is twice the number of chickens.
  • There are 480 legs in total.
So, \begin{equation} C = 2H \end{equation} \begin{equation} P = 2C \end{equation} We know that
  • Chickens have two legs
  • Horses and pigs have four legs
So, \begin{equation} 2C + 4H + 4P = 480 \end{equation} We can rewrite the equations as follows: \begin{equation} C = \frac{P}{2} \end{equation} \begin{equation} H = \frac{C}{2} = \frac{P}{4} \end{equation} So, \begin{equation} 2 \frac{P}{2} + 4 \frac{P}{4} + 4P = 480 \end{equation} \begin{equation} 6P = 480 \end{equation} \begin{equation} P = 80 \end{equation}
Correct Answer: 80
Python scratchpad
# Run Python right here in your browser
def two_sum(nums, target):
    seen = {}
    for i, n in enumerate(nums):
        if target - n in seen:
            return [seen[target - n], i]
        seen[n] = i
    return []

print(two_sum([2, 7, 11, 15], 9))  # [0, 1]
Run Python in your browser

Write and execute code — numpy, pandas & scikit-learn included — right on the question page.

Log in to start coding
Title Category Subcategory Difficulty Status
Analog Clock Angle Math QuestionsGeneralEasy
Biking With Wind Math QuestionsGeneralEasy
Birthday Candles Math QuestionsGeneralEasy
Boats on a River Math QuestionsGeneralHard
Chessboard Crossing Math QuestionsGeneralEasy
Choosing Blocks Math QuestionsGeneralEasy
Cookie Sorting Math QuestionsGeneralEasy
Counting Steps Math QuestionsGeneralEasy
Escalator Steps Math QuestionsGeneralMedium
Example
Filling a Bathtub Math QuestionsGeneralEasy
Fly vs Ant Math QuestionsGeneralMedium
Games Played Math QuestionsGeneralEasy
Going to the Beach #1 Math QuestionsGeneralMedium
How Many Dogs Math QuestionsGeneralMedium
How Many Participants Math QuestionsGeneralEasy
How Many Spiders Math QuestionsGeneralEasy
How Many Tennis Matches Math QuestionsGeneralEasy
Inflate Rate Math QuestionsGeneralHard
Example
Interview Permutations Math QuestionsGeneralEasy
Jumping Frog Math QuestionsGeneralMedium
Magic 37 Math QuestionsGeneralHard
Maximum Intersections Math QuestionsGeneralMedium
Odd Numbers Math QuestionsGeneralMedium
Painting Walls Math QuestionsGeneralEasy
Patch of Lily Pads Math QuestionsGeneralEasy
Radius of a Circle Math QuestionsGeneralHard
Rectangles On Chessboard Math QuestionsGeneralEasy
River Length #1 Math QuestionsGeneralMedium
River Length #2 Math QuestionsGeneralMedium
Sequences Math QuestionsGeneralEasy
Set of Distinct Integers Math QuestionsGeneralEasy
Sharing a Glass Math QuestionsGeneralEasy
Sheep Runs Home Math QuestionsGeneralHard
Smaller Cubes Math QuestionsGeneralMedium
Spread Set Math QuestionsGeneralHard
Squares On Chessboard Math QuestionsGeneralMedium
Summing 11 to 20 Math QuestionsGeneralEasy
Tic Tac Toe Math QuestionsGeneralEasy
Triangle on Circle Math QuestionsGeneralMedium
Unfolded Box Math QuestionsGeneralHard
Upstream or Downstream Math QuestionsGeneralMedium

Please log in to see the discussion.