The potential problem I see with trying to automate the numbering is that it would go askew if your records ever get re-ordered. For example, the second instance of Pharmacology could end up higher in the record list than the first one, meaning that the formula would cause their numbers to reverse, throwing off the reliability of the system (assuming that you want the question that ends up labeled as “Pharmacology 1” to stay that way permanently).
Believe me, I can see the benefit of having them be automatically numbered. That way you wouldn’t have to search through the list to figure out where you’re at in the numbering scheme with each subject. I just can’t think of a way to do it that would still work in the event that the record order ever shifted.
To add my 2 cents to this topic: I had something like this that I wanted to do, but like most of the people who have commented here, I didn’t want the values dynamically reassigned. The best solution I could come up with was a combination of grouping and sorting. For example: in the original example, you would group by Subject, then sort by Date Created (or some similar field type that’s more applicable for your purposes). You can then create a separate “int” field that you input manually, and each exam question can have “int” concatenated onto the end of the “Subject” string. Not perfect, but doesn’t change if you need to edit the ordering or add new questions.