Counting pulse in firmware without interrupt
We have to assume that "it's impossible" is not the right answer, so that means that we can assume that the CPU has enough power to poll the pin at a rate that's fast enough not to miss any pulses.

I don't know why you think that "you need to hardcode the transition pattern". All you need to do is find the 0&rarr;1 and 1&rarr;0 transitions and count one or the other. The only thing required is to keep track of the previous state of the pin.

In pseudocode:

count = 0;
prev_pin = read_pin();
while (true) {
    pin = read_pin();
    if (pin &amp;&amp; !prev_pin) ++count;
    prev_pin = pin;
}