Counting sheep

If you can't fall a sleep you can think a new way of "counting" sheep. Imagine a forgetful sephard, who is guarding several gates of fields. There are finite number of gates and the sephard should guide the sheep through the right gates by the task s/he is given.

In the first night the sephard should make sure that there are multiple of three sheep in the flock. So s/he simply uses three gates and guides the next sheep in the queue into the gate without looking the colour of sheep. If the last sheep goes through the third gate, then the flock is in condition.

In the next night the sephard should ensure that there are even number of both white and black sheep (other colours are not let in). Now s/he invents to use four gates (let's call them 00, 01, 10 and 11). You see, s/he always remembers the last gate and that's enough. If the first sheep is white, s/he guides it through the gate 10, if it is black, then through the gate 01. If the next one is also white, it goes through the gate 00, if it is black, then through the gate 11. If the last sheep went through the gate 11 and the next one is white, it goes through the gate 01, if black, through the gate 10, and so on. (I guess you already remember the automaton, which did the same!)

In the third night the sephard gets a really difficult task. There is coming a queue of sheep, first black sheep and after them white sheep, and there should be equal number of both. The sephard may use as many gates as s/he wants, but there is only finite number of them, and s/he doesn't know, how many sheep are coming. What happens? You can imagine further, unless you fall a sleep before our friend Pumping Lemma arrives...

Good night!