Your implication and biconditional functions seem like they would behave correctly. As for the incrementation of p q and r. I would increment an int from 0-7, change that int to its binary expression. This will be the same as the combined numbers for p q and r. Then you would just have to find a way to separate those digits so you can operate on them separately. You can use a bit mask. If you don't know what that is. This is an example
Say I have the bit string 0 1 1 and I only wanted to know what the first value is. I can do an AND operation on those bits 0 1 1 (3 & 1) = 1 Another example 1 1 1 7 & 4 = 4 ( this would be to find your p value for iteration number 7)
0 0 1 1 0 0
0 0 1 1 0 0
This method would only bring down the first value in the string. Then if I wanted to know what value existed in the first value place I would compare it with the int value 1(if true then value is 1) or 0. The second place would be 2 (if true, then the value is 1) or 0 (if true then the value is 0). The third place would be 4(if true then the value would be 1) or 0.
I hope that makes somewhat sense. There is probably a better and more elegant way but this is just what I came up with off the top of my head right now. Hope it helps
EDIT: Looking back at the pseudocode you have above. What I have said is essentially that but instead of saying p = count & 4. You would need to find the bit value because that expression would not result in what you want. It would give you either a 4 or 0 (not 1 or 0).