We post one challenging problem here every week. Solution due is 11:59 PM every Friday. We offer awards to two responders. 1. The first one with the right solution. 2. The correct solution with fewest code statements.
If we get only one correct solution, we will skip the award for the fewest code statements.
You need to create an account in this club in order to participate in this competition. The solution can use one of these three languages: Java, Python, JavaScript. You can submit your solution to this topic. Make sure your name and email account are in the end of the solution.
If you want that we indent your code correctly, please submit your code to this challenge along with a screenshot of your code in your IDE or your code file as an attachment. Remember you still need to submit your code as text here. Thanks for your participation.
Problem: A mice’s life span is 3 years. When it is 3 months old, it starts to give birth to 10 babies (5 male and 5 female) every two months. It stops bearing babies when it is 2 years and 6 months old. After 5 years of the birth of a female mice, how many offspring does it have (include those that pass away)?
//You might need to increase the java heap size in order to run the program
import java.util.ArrayList;
public class mice{
public static int age;
public mice(){
age = 0;
}
public static boolean canBirth(mice b){
if(age >= 3 && age < 36){
return true;
}
else{
return false;
}
}
public static void main(String args[]){
int totalmice = 1;
ArrayList mices = new ArrayList();
mices.add(new mice());
for(int months = 0; months <= 60; months++){
for(int i = 0; i < mices.size(); i++){
if(canBirth(mices.get(i))){
for(int j = 0; j 36){
mices.remove(i);
i–;
}
}
}
System.out.print(totalmice);
}
}
heres the code
idk why the file wont upload
https://docs.google.com/document/d/1AC1C0ggpOquAUcJrg5WLEtDPxauvo8xg-gPnMK_qZcc/edit?usp=sharing
Test upload
https://docs.google.com/document/d/1tD7ZFJmWU6sq0-zYSR0Na_k6QfIFSJIqOZCDFP5TO4s/edit?usp=sharing
The link to my document is here: https://docs.google.com/document/d/1hizkjpSunOAaZQNoRlrf4hkacnoQDDsYvPh3AkvOIfg/edit?usp=sharing
There is no winner this week. commandobolt’s code has two problems: CanBirth is true when the mice is 30 months old rather than 36 months. A static variable is shared by all class instances. You cannot use it to record the age of an individual. scienceqiu’s code does not generate babies any more when the mice is 30 months old. Actually its child can still bear babies so it will not stop at then. Also it returns one which is wrong when it is 30 months old. I tested CC13985’s code using 3 months, 6 months and 8 months. The result is different from the actual result. In 3 months the mice has only 10 kids. 6 months it has 70 kids.