I am trying to better understand how a rear derailleur (RD) works. I can understand how the RD moves inward and outward but suppose someone changes several of their cogs on the cassette. Let's just concentrate on the 3 largest cogs for this question. Let's suppose they were originally 36, 32, and 29. Next suppose the person wanted to change those to 38, 32, and 28. So we just increased the gaps by 2 teeth and 1 tooth respectively. So my question is now how does the RD "know" that the adjacent cogs to the 32 (which remained unchanged) now has wider tooth gaps and how does it handle it? A more general question is how does the RD "know" how much bigger or smaller the neighboring cog is? What I am getting at is the RD doesn't have any programming in it to tell it the gaps so how does it handle it?
Somewhat of a related variant of this question is does the RD always expect the neighboring cogs to have the same pattern of less or more teeth going inboard or outboard, thus giving us the familiar cone shaped (sloped) cassettes or freewheels? What would happen if someone made a custom cassette and had a break in that pattern such as 36, 32, 29, 30... What would do RD do when it encountered a disruption in the normal pattern when it got to the 30 tooth cog? How would the RD "know" which cogs were getting larger and which are getting smaller or do they do something to the cogs themselves to assist with this? What if someone wanted to repeat a cog such as 38, 34, 29, 29... would that work?