8
$\begingroup$

One mosquito is born at T=0 and after 2 seconds it makes a new mosquito, and another every second thereafter. All such mosquitoes have this same property and do not die. How many mosquitoes there are at T=8.5?

A friend told me the answer is 32 (which is probably wrong), but when I try it on paper I get 22 but I think it's wrong too since I don't think I get the pattern right.

I coded it in C++:

class mosq {
public:
    int cnt;
    mosq() {
        cnt = 0;
    }
};
int main() {
    std::vector<mosq> swarm, temp;
    swarm.insert(swarm.end(), mosq());
    for (int i = 0; i <= 8; i++){
        for (auto &x : swarm) {
            x.cnt++;
            if(x.cnt>2) {
                temp.insert(temp.end(), mosq());
            }
        }
        swarm.insert(swarm.end(), temp.begin(), temp.end());
        temp.clear();
    }
    getchar();
}

The result is 19 and the sequence is: 0,0,1,1,1,2,3,4,6.

But I still can't solve it on my own on paper correctly, how do you see the pattern in this kind of questions?

$\endgroup$
7
  • 1
    $\begingroup$ Do new mosquitos also make more mosquitos, or is it just the first one? And if they do, when do they start? Also two seconds after birth? $\endgroup$ May 2, 2016 at 17:24
  • 2
    $\begingroup$ if(x.cnt>2) { -> >= $\endgroup$
    – njzk2
    May 2, 2016 at 17:46
  • $\begingroup$ @njzk2 right it waited 3 ticks instead of 2. $\endgroup$
    – shinzou
    May 2, 2016 at 18:01
  • 1
    $\begingroup$ @user2357112 every mosquito behaves the same as the first. They start reproducing exactly after two seconds, so on T=2 the first mosquito made another. $\endgroup$
    – shinzou
    May 2, 2016 at 18:03
  • 1
    $\begingroup$ Think before you code. If you can't solve a problem on paper, you can't solve it with a computer. $\endgroup$ May 2, 2016 at 18:46

6 Answers 6

17
$\begingroup$

There are

34 mosquitoes

Because

$1, 1, 2, 3, 5, 8, 13, 21, 34 \dots$
Are the number of mosquitoes at $T=0, 1, 2 \dots$
Because the number of mosquitoes ready to make a new one at $T=n+1$ is the number at $T=n-1$ so we have $(T=n-1) + (T=n)$ mosquitoes then.

$\endgroup$
5
  • 1
    $\begingroup$ An explanation of why this follows the indicated sequence would improve the answer. $\endgroup$ May 2, 2016 at 16:33
  • $\begingroup$ @user3294068 just edited with an explaination $\endgroup$
    – Paul Evans
    May 2, 2016 at 16:34
  • 3
    $\begingroup$ Which is actually Fibonacci huh. $\endgroup$
    – shinzou
    May 2, 2016 at 16:35
  • 1
    $\begingroup$ @kuhaku - yes it's Fibonacci $\endgroup$ May 2, 2016 at 16:35
  • 6
    $\begingroup$ @kuhaku - not a big "huh". This is exactly how Fibonacci came across the sequence (but with pairs of rabbits instead of mosquitos, and months instead of seconds). $\endgroup$ May 2, 2016 at 16:51
8
$\begingroup$

Paul Evans has it, but just for completeness here is an explicit function in terms of the variables of the posed problem:

def mosquitos(stopTime=8.5): adults = 0 juveniles = 0 infants = 1 time = 0 while time <= stopTime: yield time, adults + juveniles + infants adults += juveniles juveniles = infants infants = adults time += 1

use case:

>>> for time, count in mosquitos(): ... time, count ... (0, 1) (1, 1) (2, 2) (3, 3) (4, 5) (5, 8) (6, 13) (7, 21) (8, 34)

How the problem is represented

At time 0 there is 1 infant, at time 1 that infant becomes a juvenile and at time 2 the same mosquito becomes an adult. At every time step of one second the number of new adults increases as the juveniles mature to adults, the new juveniles are simply the old infants, and the new infants are equal in number to all of the adults.

$\endgroup$
9
  • $\begingroup$ Is that python? $\endgroup$
    – shinzou
    May 2, 2016 at 16:43
  • 1
    $\begingroup$ @kuhaku yes it is, keeping it nice and simple :) $\endgroup$ May 2, 2016 at 16:44
  • 2
    $\begingroup$ And your "adults + juveniles + infants" model of abstracting the problem is clear + simple too +1 $\endgroup$
    – Paul Evans
    May 2, 2016 at 17:16
  • 2
    $\begingroup$ Nice. Been using Python for ten years, didn't realise you could just put an expression in a for loop like that to have the interactive interpreter display it. Thank-you! $\endgroup$ May 2, 2016 at 17:36
  • 2
    $\begingroup$ @JonathanHartley Glad to spread some knowledge! The function call results in a generator, which is an iterable; very useful. $\endgroup$ May 2, 2016 at 17:45
4
$\begingroup$

Writing m for baby mosquitoes and M for adult mosquitoes:

t=0 m
t=1 M
t=2 Mm
t=3 MMm
t=4 MMMmm
t=5 MMMMMmmm
t=6 MMMMMMMMmmmmm
t=7 MMMMMMMMMMMMMmmmmmmmm
t=8 MMMMMMMMMMMMMMMMMMMMMmmmmmmmmmmmmm

Baby mosquitoes grow into adult mosquitoes. Each adult mosquito produces a baby mosquito for the next generation.

The recurrence relation is:

adults(t+1) = adults(t) + babies(t)  // babies grow into adults
babies(t+1) = adults(t)              // adults each produce a baby

Thus

total(8) = adults(8) + babies(8) = 21 + 13 = 34

There are 34 mosquitoes at t=8.


If you play about with the recurrence relation you can deduce

total(t+2) = adults(t+2) + babies(t+2) 
           = adults(t+1) + babies(t+1) + adults(t+1) 
           = total(t+1) + total(t)

The sequence 1,1,2,3,5,8,13,21,34 is the famous Fibonacci sequence. (Fibonacci wrote of rabbits rather than mosquitoes, but the setup is otherwise identical.)

$\endgroup$
2
  • $\begingroup$ I tried to illustrate it similarly but I mixed it up in higher numbers, that's a more simple approach IMO. $\endgroup$
    – shinzou
    May 2, 2016 at 18:47
  • $\begingroup$ upvoted for mentioning Fibonacci's rabbits. $\endgroup$ May 2, 2016 at 19:15
1
$\begingroup$

At t= 8.5, there are

34 mosquitoes.

Working on how to explain it, but basically I made a tree where mosquito 0 makes 7 other mosquitoes, each with their own tree, and it comes out to that number

$\endgroup$
1
$\begingroup$

One mosquito is born at T=0 and after 2 seconds makes a new mosquito every second, how many mosquitos there are at T=8.5?

It is important to consider wording when looking at problems like this.

For example, an alternative and equally valid interpretation would be:

7 total mosquitos. The question indicates that the first mosquito is the mosquito which is actually making new ones. From start to finish, it takes 1 second to make each mosquito. So the timeline looks like:

T=0 (1 mosquitos)

T=1 (1 mosquitos)

T=2 (1 mosquitos, one started)

T=3 (2 mosquitos, 1 started, 1 new completed)

T=4 (3 mosquitos, 1 started, 1 new completed)

T=5 (4 mosquitos, 1 started, 1 new completed)

T=6 (5 mosquitos, 1 started, 1 new completed)

T=7 (6 mosquitos, 1 started, 1 new completed)

T=8 (7 mosquitos, 1 started, 1 new completed)

T=8.5 (7 mosquitos, 1 in-progress, 0 new completed)

Without clarification it is impossible to know what interpretation is correct. I should note that many "trick" questions often result in scenarios such as what I have presented as being the answer.

$\endgroup$
4
  • $\begingroup$ But you assume that the first mosquito is unique or the only fertile one or whatever. $\endgroup$
    – shinzou
    May 2, 2016 at 18:04
  • 1
    $\begingroup$ @kuhaku that's exactly what your problem statement says though. It does not state that any other mosquitoes are able to make new ones, it just says that One mosquito born at T=0 makes a new mosquito every second. It says nothing at all about other mosquitos and requires an inference not given in the stated question in order to assume others do this, too. $\endgroup$
    – enderland
    May 2, 2016 at 18:07
  • $\begingroup$ Fair point. However, it seems pretty obvious that is not what @kuhaku meant, this could probably just be a comment rather than an answer. Let's update the question... $\endgroup$ May 2, 2016 at 18:07
  • 1
    $\begingroup$ @JonathanAllan things are only as obvious as explicitly stated when it comes to puzzles/riddles. Changing a definition in order to fix problems in the puzzle formulation seems... rather lame. $\endgroup$
    – enderland
    May 2, 2016 at 18:09
0
$\begingroup$

Depending on how you interpret the question, adults might begin spawning at 3 seconds after their birth. The ambiguity lies among "AFTER two seconds" and "every second". If this is the case, then the answer is 13.

$\endgroup$

Not the answer you're looking for? Browse other questions tagged or ask your own question.