Suppose you are trying to understand how the population of two types of animals will evolve over time. You have bunnies and foxes. Unfortunately, foxes like to eat bunnies. So, even though the bunny population grows every year when baby bunnies are born, it also goes down because some of them are eaten. Would the fox population keep increasing in size until there are no bunnies left? Not so. The fox population is directly linked to the bunny population, their main food source. What will happen over time if you start with a given population of bunnies and foxes? Who will win out? Will they balance each other? Suppose $$bpop$$ and $$fpop$$ are the population of bunnies and foxes currently. Then, next year’s population of bunnies (bpop_next) and foxes (fpop_next) are given by: bpop_next = $$(10*bpop)/(1+0.1*bpop) - 0.05*bpop*fpop$$ fpop_next = $$0.4 * fpop + 0.02 * fpop * bpop$$ What will be the population of bunnies and foxes next year? Your program first should read the population of bunnie and foxes using raw_input, compute and print the next years’ population for both based on this current value. Now, for the final challenge, use Year 2 values to find year 3 populations of bunnies and foxes. Do not create new variables, just use the same variables you currently have. Once you figure this out, you can repeat this part 2 more times to find the population in Year 5.
## Function to determine the next year's bunny and fox population def bunny_pop(bpop,fpop): bpop_next = max(0,(10*bpop)/(1+0.1*bpop) - 0.05*bpop*fpop) return int(bpop_next) def fox_pop(bpop,fpop): fpop_next = max(0,0.4 * fpop + 0.02 * fpop * bpop) return int(fpop_next) ## Initial bunny and fox population bpop = int(raw_input("Number of bunnies: ")) fpop = int(raw_input("Number of foxes: ")) ## Table for bunny and fox population for 5 years print "Year 1:", bpop, fpop print "Year 2:", bunny_pop(bpop,fpop), fox_pop(bpop,fpop) print "Year 3:", bunny_pop(bunny_pop(bpop,fpop), fox_pop(bpop,fpop)), fox_pop(bunny_pop(bpop,fpop), fox_pop(bpop,fpop)) print "Year 4:", bunny_pop(bunny_pop(bunny_pop(bpop,fpop), fox_pop(bpop,fpop)), fox_pop(bunny_pop(bpop,fpop), fox_pop(bpop,fpop))), fox_pop(bunny_pop(bunny_pop(bpop,fpop), fox_pop(bpop,fpop)), fox_pop(bunny_pop(bpop,fpop), fox_pop(bpop,fpop))) print "year 5:", bunny_pop(bunny_pop(bunny_pop(bunny_pop(bpop,fpop), fox_pop(bpop,fpop)), fox_pop(bunny_pop(bpop,fpop), fox_pop(bpop,fpop))), fox_pop(bunny_pop(bunny_pop(bpop,fpop), fox_pop(bpop,fpop)), fox_pop(bunny_pop(bpop,fpop), fox_pop(bpop,fpop)))), fox_pop(bunny_pop(bunny_pop(bunny_pop(bpop,fpop), fox_pop(bpop,fpop)), fox_pop(bunny_pop(bpop,fpop), fox_pop(bpop,fpop))), fox_pop(bunny_pop(bunny_pop(bpop,fpop), fox_pop(bpop,fpop)), fox_pop(bunny_pop(bpop,fpop), fox_pop(bpop,fpop))))
Calculate the area enclosed by the graphs of $$f(y) = y^2 − 1$$ and $$g(y) = y^2 − \frac{1}{8}y^4 + 1$$.
$$\int_{-2}^2 (2 - \frac{1}{8}y^4)\mathrm{d}y $$ $$ = \frac{16}{5} - (-\frac{16}{5}) $$ $$ = \frac{32}{5} $$
Create a C++ that EFFICIENTLY checks if a string of length $$n$$ is a palindrome.
#include <iostream> #include <algorithm> #include <string> int main() { std::string word; std::cin >> word; if (equal(word.begin(), word.begin() + word.size()/2, word.rbegin())) std::cout << "\n" + word + " is a palindrome." << endl; else std::cout << "\n" + word + " is not a palindrome." << endl; }